threadpool: Fix leak in ast_threadpool_serializer_group error path.
authorCorey Farrell <git@cfware.com>
Wed, 13 Jul 2016 16:30:58 +0000 (12:30 -0400)
committerCorey Farrell <git@cfware.com>
Wed, 13 Jul 2016 16:47:56 +0000 (11:47 -0500)
ast_threadpool_serializer_group leaks a reference to ser when listener
is allocated but tps is not.  Although listener takes the reference to
ser cleanup functions are not run without tps.

ASTERISK-26191 #close

Change-Id: Ie3ccf69a3f1e676c2ef62a77067c0cb57dc9a585

main/threadpool.c

index 9cd33ab..6240b73 100644 (file)
@@ -1384,10 +1384,12 @@ struct ast_taskprocessor *ast_threadpool_serializer_group(const char *name,
                ao2_ref(ser, -1);
                return NULL;
        }
-       /* ser ref transferred to listener */
 
        tps = ast_taskprocessor_create_with_listener(name, listener);
-       if (tps && shutdown_group) {
+       if (!tps) {
+               /* ser ref transferred to listener but not cleaned without tps */
+               ao2_ref(ser, -1);
+       } else if (shutdown_group) {
                serializer_shutdown_group_inc(shutdown_group);
        }