]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Ensure REF_DEBUG records entrys for attempts to ao2_ref an invalid object
authorCorey Farrell <git@cfware.com>
Fri, 27 Jun 2014 19:24:20 +0000 (19:24 +0000)
committerCorey Farrell <git@cfware.com>
Fri, 27 Jun 2014 19:24:20 +0000 (19:24 +0000)
This change ensures that __ao2_ref_debug writes to ref_log when given a
non-NULL pointer to an invalid ao2 object.  This is to ensure that we
record any attempt manipulate references of already freed objects.

ASTERISK-23948 #close
Reported by: Corey Farrell
Review: https://reviewboard.asterisk.org/r/3677/

git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.8@417500 65c4cc65-6c06-0410-ace0-fbb531ad65f3

main/astobj2.c

index 82dc8a3460d078349a82d7930a6af7f662a17726..8efc9391b9c83cb33c9e58f43e85ef6a5193de23 100644 (file)
@@ -220,12 +220,8 @@ int __ao2_ref_debug(void *user_data, const int delta, const char *tag, const cha
 {
        struct astobj2 *obj = INTERNAL_OBJ(user_data);
 
-       if (obj == NULL) {
-               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, funcname, tag);
                        fflush(ref_log);
                } else if (delta != 0) {
@@ -234,6 +230,11 @@ int __ao2_ref_debug(void *user_data, const int delta, const char *tag, const cha
                        fflush(ref_log);
                }
        }
+
+       if (obj == NULL) {
+               return -1;
+       }
+
        return internal_ao2_ref(user_data, delta);
 }