Index: main/astobj2.c =================================================================== --- main/astobj2.c (revision 417247) +++ main/astobj2.c (working copy) @@ -499,14 +499,8 @@ { struct astobj2 *obj = INTERNAL_OBJ(user_data); - if (obj == NULL) { - ast_log_backtrace(); - ast_assert(0); - return -1; - } - - if (ref_log) { - if (obj->priv_data.ref_counter + delta == 0) { + if (ref_log && user_data) { + if (obj && obj->priv_data.ref_counter + delta == 0) { fprintf(ref_log, "%p,%d,%d,%s,%d,%s,**destructor**,%s\n", user_data, delta, ast_get_tid(), file, line, func, tag); fflush(ref_log); } else if (delta != 0) { @@ -515,6 +509,13 @@ fflush(ref_log); } } + + if (obj == NULL) { + ast_log_backtrace(); + ast_assert(0); + return -1; + } + return internal_ao2_ref(user_data, delta, file, line, func); }