<p>Corey Farrell has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/7083">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res_pjsip_pubsub: Fix multiple leaks on failure to append vectors.<br><br>Change-Id: I68ece0073ea79667ca41eb10405f516f1d30d482<br>---<br>M res/res_pjsip_pubsub.c<br>1 file changed, 19 insertions(+), 5 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/83/7083/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/res/res_pjsip_pubsub.c b/res/res_pjsip_pubsub.c<br>index e2c6f6c..e75a0ae 100644<br>--- a/res/res_pjsip_pubsub.c<br>+++ b/res/res_pjsip_pubsub.c<br>@@ -938,7 +938,9 @@<br>                            }<br>                             ast_debug(2, "Subscription to leaf resource %s resulted in success. Adding to parent %s\n",<br>                                                 resource, parent->resource);<br>-                              AST_VECTOR_APPEND(&parent->children, current);<br>+                                if (AST_VECTOR_APPEND(&parent->children, current)) {<br>+                                  tree_node_destroy(current);<br>+                          }<br>                     } else {<br>                              ast_debug(2, "Subscription to leaf resource %s resulted in error response %d\n",<br>                                            resource, resp);<br>@@ -953,7 +955,9 @@<br>                         build_node_children(endpoint, handler, child_list, current, visited);<br>                         if (AST_VECTOR_SIZE(&current->children) > 0) {<br>                              ast_debug(1, "List %s had no successful children.\n", resource);<br>-                           AST_VECTOR_APPEND(&parent->children, current);<br>+                                if (AST_VECTOR_APPEND(&parent->children, current)) {<br>+                                  tree_node_destroy(current);<br>+                          }<br>                     } else {<br>                              ast_debug(2, "List %s had successful children. Adding to parent %s\n",<br>                                              resource, parent->resource);<br>@@ -1216,6 +1220,8 @@<br>                if (AST_VECTOR_APPEND(&sub->children, child)) {<br>                        ast_debug(1, "Child subscription to resource %s could not be appended\n",<br>                                   child_node->resource);<br>+                    destroy_subscription(child);<br>+                 ao2_cleanup(tree);<br>            }<br>     }<br> <br>@@ -2161,7 +2167,9 @@<br>   bp->part->body = body;<br>  pj_list_insert_before(&bp->part->hdr, bp->cid);<br> <br>-      AST_VECTOR_APPEND(parts, bp);<br>+        if (AST_VECTOR_APPEND(parts, bp)) {<br>+          ast_free(bp);<br>+        }<br> }<br> <br> /*!<br>@@ -4662,7 +4670,10 @@<br>                        ast_log(LOG_WARNING, "Ignoring duplicated list item '%s'\n", item);<br>                         continue;<br>             }<br>-            if (AST_VECTOR_APPEND(&list->items, ast_strdup(item))) {<br>+<br>+           item = ast_strdup(item);<br>+             if (!item || AST_VECTOR_APPEND(&list->items, item)) {<br>+                 ast_free(item);<br>                       return -1;<br>            }<br>     }<br>@@ -4798,7 +4809,10 @@<br>     ast_copy_string(list->event, event, sizeof(list->event));<br> <br>    for (i = 0; i < num_resources; ++i) {<br>-             if (AST_VECTOR_APPEND(&list->items, ast_strdup(resources[i]))) {<br>+              char *resource = ast_strdup(resources[i]);<br>+<br>+                if (!resource || AST_VECTOR_APPEND(&list->items, resource)) {<br>+                 ast_free(resource);<br>                   return -1;<br>            }<br>     }<br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/7083">change 7083</a>. To unsubscribe, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/7083"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 13 </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: I68ece0073ea79667ca41eb10405f516f1d30d482 </div>
<div style="display:none"> Gerrit-Change-Number: 7083 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Corey Farrell <git@cfware.com> </div>