]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
backport astobj2 race condition fix. This function is the exact same as trunk
authorRussell Bryant <russell@russellbryant.com>
Mon, 10 Sep 2007 19:53:17 +0000 (19:53 +0000)
committerRussell Bryant <russell@russellbryant.com>
Mon, 10 Sep 2007 19:53:17 +0000 (19:53 +0000)
so it applies here as well.

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

main/astobj2.c

index 5fef8b1fa3f05e28aad7ecb40620b72bdafc2ccd..0f23dfc08371a07b8409fda62339f73bb316f7fb 100644 (file)
@@ -513,6 +513,7 @@ void * ao2_iterator_next(struct ao2_iterator *a)
 {
        int lim;
        struct bucket_list *p = NULL;
+       void *ret = NULL;
 
        if (INTERNAL_OBJ(a->c) == NULL)
                return NULL;
@@ -553,14 +554,15 @@ found:
                a->version = p->version;
                a->obj = p;
                a->c_version = a->c->version;
+               ret = EXTERNAL_OBJ(p->astobj);
                /* inc refcount of returned object */
-               ao2_ref(EXTERNAL_OBJ(p->astobj), 1);
+               ao2_ref(ret, 1);
        }
 
        if (!(a->flags & F_AO2I_DONTLOCK))
                ao2_unlock(a->c);
 
-       return p ? EXTERNAL_OBJ(p->astobj) : NULL;
+       return ret;
 }
 
 /* callback for destroying container.