[asterisk-commits] mjordan: trunk r366917 - in /trunk: ./ apps/ channels/ channels/sip/ funcs/ m...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri May 18 09:44:13 CDT 2012


Author: mjordan
Date: Fri May 18 09:43:44 2012
New Revision: 366917

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=366917
Log:
Fix a variety of memory leaks

This patch addresses a number of memory leaks in a variety of modules that were
found by a static analysis tool.  A brief summary of the changes:

* app_minivm:       free ast_str objects on off nominal paths
* app_page:         free the ast_dial object if the requested channel technology
                    cannot be appended to the dialing structure
* app_queue:        if a penalty rule failed to match any existing rule list
                    names, the created rule would not be inserted and its memory
                    would be leaked
* app_read:         dispose of the created silence detector in the presence of
                    off nominal circumstances
* app_voicemail:    dispose of an allocated unique ID field for MWI event
                    un-subscribe requests in off nominal paths; dispose of
                    configuration objects when using the secret.conf option
* chan_dahdi:       dispose of the allocated frame produced by ast_dsp_process
* chan_iax2:        properly unref peer in CLI command "iax2 unregister"
* chan_sip:         dispose of the allocated frame produced by sip_rtp_read's
                    call of ast_dsp_process; free memory in parse unit tests
* func_dialgroup:   properly deref ao2 object grhead in nominal path of
                    dialgroup_read
* func_odbc:        free resultset in off nominal paths of odbc_read
* cli:              free match_list in off nominal paths of CLI match completion
* config:           free comment_buffer/list_buffer when configuration file load
                    is unchanged; free the same buffers any time they were
                    created and config files were processed
* data:             free XML nodes in various places
* enum:             free context buffer in off nominal paths
* features:         free ast_call_feature in off nominal paths of applicationmap
                    config processing
* netsock2:         users of ast_sockaddr_resolve pass in an ast_sockaddr struct
                    that is allocated by the method.  Failures in
                    ast_sockaddr_resolve could result in the users of the method
                    not knowing whether or not the buffer was allocated.  The
                    method will now not allocate the ast_sockaddr struct if it
                    will return failure.
* pbx:              cleanup hash table traversals in off nominal paths; free
                    ignore pattern buffer if it already exists for the specified
                    context
* xmldoc:           cleanup various nodes when we no longer need them
* main/editline:    various cleanup of pointers not being freed before being
                    assigned to other memory, cleanup along off nominal paths
* menuselect/mxml:  cleanup of value buffer for an attribute when that attribute
                    did not specify a value
* res_calendar*:    responses are allocated via the various *_request method
                    returns and should not be allocated in the various
                    write_event methods; ensure attendee buffer is freed if no
                    data exists in the parsed node; ensure that calendar objects
                    are de-ref'd appropriately
* res_jabber:       free buffer in off nominal path
* res_musiconhold:  close the DIR* object in off nominal paths
* res_rtp_asterisk: if we run out of ports, close the rtp socket object and free
                    the rtp object
* res_srtp:         if we fail to create the session in libsrtp, destroy the
                    temporary ast_srtp object

(issue ASTERISK-19665)
Reported by: Matt Jordan

Review: https://reviewboard.asterisk.org/r/1922
........

Merged revisions 366880 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........

Merged revisions 366881 from http://svn.asterisk.org/svn/asterisk/branches/10

Modified:
    trunk/   (props changed)
    trunk/apps/app_minivm.c
    trunk/apps/app_page.c
    trunk/apps/app_queue.c
    trunk/apps/app_record.c
    trunk/apps/app_voicemail.c
    trunk/channels/chan_dahdi.c
    trunk/channels/chan_iax2.c
    trunk/channels/chan_sip.c
    trunk/channels/sip/config_parser.c
    trunk/funcs/func_dialgroup.c
    trunk/funcs/func_odbc.c
    trunk/main/cli.c
    trunk/main/config.c
    trunk/main/data.c
    trunk/main/editline/readline.c
    trunk/main/editline/term.c
    trunk/main/editline/tokenizer.c
    trunk/main/enum.c
    trunk/main/features.c
    trunk/main/netsock2.c
    trunk/main/pbx.c
    trunk/main/xmldoc.c
    trunk/res/res_calendar.c
    trunk/res/res_calendar_caldav.c
    trunk/res/res_calendar_exchange.c
    trunk/res/res_calendar_icalendar.c
    trunk/res/res_jabber.c
    trunk/res/res_rtp_asterisk.c
    trunk/res/res_srtp.c

Propchange: trunk/
------------------------------------------------------------------------------
Binary property 'branch-10-merged' - no diff available.

Modified: trunk/apps/app_minivm.c
URL: http://svnview.digium.com/svn/asterisk/trunk/apps/app_minivm.c?view=diff&rev=366917&r1=366916&r2=366917
==============================================================================
--- trunk/apps/app_minivm.c (original)
+++ trunk/apps/app_minivm.c Fri May 18 09:43:44 2012
@@ -1255,6 +1255,8 @@
 
 	if (ast_strlen_zero(email)) {
 		ast_log(LOG_WARNING, "No address to send message to.\n");
+		ast_free(str1);
+		ast_free(str2);
 		return -1;	
 	}
 
@@ -1309,11 +1311,15 @@
 	}
 	if (!p) {
 		ast_log(LOG_WARNING, "Unable to open temporary file '%s'\n", tmp);
+		ast_free(str1);
+		ast_free(str2);
 		return -1;
 	}
 	/* Allocate channel used for chanvar substitution */
 	ast = ast_dummy_channel_alloc();
 	if (!ast) {
+		ast_free(str1);
+		ast_free(str2);
 		return -1;
 	}
 

Modified: trunk/apps/app_page.c
URL: http://svnview.digium.com/svn/asterisk/trunk/apps/app_page.c?view=diff&rev=366917&r1=366916&r2=366917
==============================================================================
--- trunk/apps/app_page.c (original)
+++ trunk/apps/app_page.c Fri May 18 09:43:44 2012
@@ -270,6 +270,7 @@
 		/* Append technology and resource */
 		if (ast_dial_append(dial, tech, resource) == -1) {
 			ast_log(LOG_ERROR, "Failed to add %s to outbound dial\n", tech);
+			ast_dial_destroy(dial);
 			continue;
 		}
 

Modified: trunk/apps/app_queue.c
URL: http://svnview.digium.com/svn/asterisk/trunk/apps/app_queue.c?view=diff&rev=366917&r1=366916&r2=366917
==============================================================================
--- trunk/apps/app_queue.c (original)
+++ trunk/apps/app_queue.c Fri May 18 09:43:44 2012
@@ -1973,9 +1973,17 @@
 	
 		if (!inserted) {
 			AST_LIST_INSERT_TAIL(&rl_iter->rules, rule, list);
-		}
-	}
-
+			inserted = 1;
+		}
+
+		break;
+	}
+
+	if (!inserted) {
+		ast_log(LOG_WARNING, "Unknown rule list name %s; ignoring.\n", list_name);
+		ast_free(rule);
+		return -1;
+	}
 	return 0;
 }
 
@@ -4538,6 +4546,7 @@
 	ast_channel_lock(qe->chan);
 	if (!(ds = ast_datastore_alloc(&queue_transfer_info, NULL))) {
 		ast_channel_unlock(qe->chan);
+		ast_free(qtds);
 		ast_log(LOG_WARNING, "Unable to create transfer datastore. queue_log will not show attended transfer\n");
 		return NULL;
 	}

Modified: trunk/apps/app_record.c
URL: http://svnview.digium.com/svn/asterisk/trunk/apps/app_record.c?view=diff&rev=366917&r1=366916&r2=366917
==============================================================================
--- trunk/apps/app_record.c (original)
+++ trunk/apps/app_record.c Fri May 18 09:43:44 2012
@@ -415,12 +415,14 @@
 out:
 	if ((silence > 0) && rfmt.id) {
 		res = ast_set_read_format(chan, &rfmt);
-		if (res)
+		if (res) {
 			ast_log(LOG_WARNING, "Unable to restore read format on '%s'\n", ast_channel_name(chan));
-		if (sildet)
-			ast_dsp_free(sildet);
-	}
-
+		}
+	}
+
+	if (sildet) {
+		ast_dsp_free(sildet);
+	}
 	return res;
 }
 

Modified: trunk/apps/app_voicemail.c
URL: http://svnview.digium.com/svn/asterisk/trunk/apps/app_voicemail.c?view=diff&rev=366917&r1=366916&r2=366917
==============================================================================
--- trunk/apps/app_voicemail.c (original)
+++ trunk/apps/app_voicemail.c Fri May 18 09:43:44 2012
@@ -11728,16 +11728,22 @@
 static void mwi_unsub_event_cb(const struct ast_event *event, void *userdata)
 {
 	uint32_t u, *uniqueid = ast_calloc(1, sizeof(*uniqueid));
-	if (ast_event_get_type(event) != AST_EVENT_UNSUB)
-		return;
-
-	if (ast_event_get_ie_uint(event, AST_EVENT_IE_EVENTTYPE) != AST_EVENT_MWI)
-		return;
 
 	if (!uniqueid) {
 		ast_log(LOG_ERROR, "Unable to allocate memory for uniqueid\n");
 		return;
 	}
+
+	if (ast_event_get_type(event) != AST_EVENT_UNSUB) {
+		ast_free(uniqueid);
+		return;
+	}
+
+	if (ast_event_get_ie_uint(event, AST_EVENT_IE_EVENTTYPE) != AST_EVENT_MWI) {
+		ast_free(uniqueid);
+		return;
+	}
+
 	u = ast_event_get_ie_uint(event, AST_EVENT_IE_UNIQUEID);
 	*uniqueid = u;
 	if (ast_taskprocessor_push(mwi_subscription_tps, handle_unsubscribe, uniqueid) < 0) {
@@ -12728,8 +12734,10 @@
 		const char *val = ast_variable_retrieve(pwconf, "general", "password");
 		if (val) {
 			ast_copy_string(password, val, passwordlen);
- 			return;
-		}
+			ast_config_destroy(pwconf);
+			return;
+		}
+		ast_config_destroy(pwconf);
 	}
 	ast_log(LOG_NOTICE, "Failed reading voicemail password from %s, using secret from config file\n", secretfn);
 }
@@ -12738,26 +12746,33 @@
 	struct ast_config *conf;
 	struct ast_category *cat;
 	struct ast_variable *var;
-
-	if (!(conf=ast_config_new())) {
+	int res = -1;
+
+	if (!(conf = ast_config_new())) {
 		ast_log(LOG_ERROR, "Error creating new config structure\n");
-		return -1;
-	}
-	if (!(cat=ast_category_new("general","",1))) {
+		return res;
+	}
+	if (!(cat = ast_category_new("general", "", 1))) {
 		ast_log(LOG_ERROR, "Error creating new category structure\n");
-		return -1;
-	}
-	if (!(var=ast_variable_new("password",password,""))) {
+		ast_config_destroy(conf);
+		return res;
+	}
+	if (!(var = ast_variable_new("password", password, ""))) {
 		ast_log(LOG_ERROR, "Error creating new variable structure\n");
-		return -1;
-	}
-	ast_category_append(conf,cat);
-	ast_variable_append(cat,var);
-	if (ast_config_text_file_save(secretfn, conf, "app_voicemail")) {
+		ast_config_destroy(conf);
+		ast_category_destroy(cat);
+		return res;
+	}
+	ast_category_append(conf, cat);
+	ast_variable_append(cat, var);
+	if (!ast_config_text_file_save(secretfn, conf, "app_voicemail")) {
+		res = 0;
+	} else {
 		ast_log(LOG_ERROR, "Error writing voicemail password to %s\n", secretfn);
-		return -1;
-	}
-	return 0;
+	}
+
+	ast_config_destroy(conf);
+	return res;
 }
 
 static int vmsayname_exec(struct ast_channel *chan, const char *data)

Modified: trunk/channels/chan_dahdi.c
URL: http://svnview.digium.com/svn/asterisk/trunk/channels/chan_dahdi.c?view=diff&rev=366917&r1=366916&r2=366917
==============================================================================
--- trunk/channels/chan_dahdi.c (original)
+++ trunk/channels/chan_dahdi.c Fri May 18 09:43:44 2012
@@ -9315,6 +9315,7 @@
 					 * Treat this as a "hangup" instead of a "busy" on the
 					 * assumption that a busy means the incoming call went away.
 					 */
+					ast_frfree(f);
 					f = NULL;
 				}
 			} else if (p->dialtone_detect && !p->outgoing && f->frametype == AST_FRAME_VOICE) {
@@ -9345,7 +9346,8 @@
 				if (ast_tvdiff_ms(ast_tvnow(), p->waitingfordt) >= p->waitfordialtone ) {
 					p->waitingfordt.tv_sec = 0;
 					ast_log(LOG_WARNING, "Never saw dialtone on channel %d\n", p->channel);
-					f=NULL;
+					ast_frfree(f);
+					f = NULL;
 				} else if (f->frametype == AST_FRAME_VOICE) {
 					f->frametype = AST_FRAME_NULL;
 					f->subclass.integer = 0;
@@ -9360,6 +9362,7 @@
 								ast_log(LOG_WARNING, "Unable to initiate dialing on trunk channel %d\n", p->channel);
 								p->dop.dialstr[0] = '\0';
 								ast_mutex_unlock(&p->lock);
+								ast_frfree(f);
 								return NULL;
 							} else {
 								ast_debug(1, "Sent deferred digit string: %s\n", p->dop.dialstr);

Modified: trunk/channels/chan_iax2.c
URL: http://svnview.digium.com/svn/asterisk/trunk/channels/chan_iax2.c?view=diff&rev=366917&r1=366916&r2=366917
==============================================================================
--- trunk/channels/chan_iax2.c (original)
+++ trunk/channels/chan_iax2.c Fri May 18 09:43:44 2012
@@ -6899,6 +6899,7 @@
 		} else {
 			ast_cli(a->fd, "Peer %s not registered\n", a->argv[2]);
 		}
+		peer_unref(p);
 	} else {
 		ast_cli(a->fd, "Peer unknown: %s. Not unregistered\n", a->argv[2]);
 	}
@@ -9847,6 +9848,7 @@
 		}
 		varlist = ast_calloc(1, sizeof(*varlist));
 		if (!varlist) {
+			ast_datastore_free(variablestore);
 			ast_log(LOG_ERROR, "Unable to assign new variable '%s'\n", data);
 			return -1;
 		}

Modified: trunk/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/trunk/channels/chan_sip.c?view=diff&rev=366917&r1=366916&r2=366917
==============================================================================
--- trunk/channels/chan_sip.c (original)
+++ trunk/channels/chan_sip.c Fri May 18 09:43:44 2012
@@ -7657,6 +7657,7 @@
 				if (ast_async_goto(ast, target_context, "fax", 1)) {
 					ast_log(LOG_NOTICE, "Failed to async goto '%s' into fax of '%s'\n", ast_channel_name(ast), target_context);
 				}
+				ast_frfree(fr);
 				fr = &ast_null_frame;
 			} else {
 				ast_channel_lock(ast);
@@ -7668,6 +7669,7 @@
 
 	/* Only allow audio through if they sent progress with SDP, or if the channel is actually answered */
 	if (fr && fr->frametype == AST_FRAME_VOICE && p->invitestate != INV_EARLY_MEDIA && ast_channel_state(ast) != AST_STATE_UP) {
+		ast_frfree(fr);
 		fr = &ast_null_frame;
 	}
 

Modified: trunk/channels/sip/config_parser.c
URL: http://svnview.digium.com/svn/asterisk/trunk/channels/sip/config_parser.c?view=diff&rev=366917&r1=366916&r2=366917
==============================================================================
--- trunk/channels/sip/config_parser.c (original)
+++ trunk/channels/sip/config_parser.c Fri May 18 09:43:44 2012
@@ -597,6 +597,8 @@
 		ast_test_status_update(test, "Test 13, add domain port failed.\n");
 		res = AST_TEST_FAIL;
 	}
+	ast_string_field_free_memory(reg);
+	ast_free(reg);
 
 	/* ---Test reg14, domain port without secret --- */
 	if (!(reg = ast_calloc_with_stringfields(1, struct sip_registry, 256))) {
@@ -623,7 +625,9 @@
 
 		ast_test_status_update(test, "Test 14, domain port without secret failed.\n");
 		res = AST_TEST_FAIL;
-}
+	}
+	ast_string_field_free_memory(reg);
+	ast_free(reg);
 
 
 	return res;

Modified: trunk/funcs/func_dialgroup.c
URL: http://svnview.digium.com/svn/asterisk/trunk/funcs/func_dialgroup.c?view=diff&rev=366917&r1=366916&r2=366917
==============================================================================
--- trunk/funcs/func_dialgroup.c (original)
+++ trunk/funcs/func_dialgroup.c Fri May 18 09:43:44 2012
@@ -165,6 +165,7 @@
 		ao2_ref(entry, -1);
 	}
 	ao2_iterator_destroy(&i);
+	ao2_ref(grhead, -1);
 
 	return res;
 }

Modified: trunk/funcs/func_odbc.c
URL: http://svnview.digium.com/svn/asterisk/trunk/funcs/func_odbc.c?view=diff&rev=366917&r1=366916&r2=366917
==============================================================================
--- trunk/funcs/func_odbc.c (original)
+++ trunk/funcs/func_odbc.c Fri May 18 09:43:44 2012
@@ -539,6 +539,7 @@
 			pbx_builtin_setvar_helper(chan, "ODBCROWS", rowcount);
 			ast_autoservice_stop(chan);
 		}
+		ast_free(resultset);
 		return -1;
 	}
 
@@ -553,6 +554,7 @@
 			pbx_builtin_setvar_helper(chan, "ODBCROWS", rowcount);
 			ast_autoservice_stop(chan);
 		}
+		ast_free(resultset);
 		return -1;
 	}
 
@@ -578,6 +580,7 @@
 			pbx_builtin_setvar_helper(chan, "ODBCSTATUS", status);
 			ast_autoservice_stop(chan);
 		}
+		ast_free(resultset);
 		return res1;
 	}
 

Modified: trunk/main/cli.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/cli.c?view=diff&rev=366917&r1=366916&r2=366917
==============================================================================
--- trunk/main/cli.c (original)
+++ trunk/main/cli.c Fri May 18 09:43:44 2012
@@ -2350,8 +2350,10 @@
 		max_equal = i;
 	}
 
-	if (!(retstr = ast_malloc(max_equal + 1)))
-		return NULL;
+	if (!(retstr = ast_malloc(max_equal + 1))) {
+		ast_free(match_list);
+		return NULL;
+	}
 
 	ast_copy_string(retstr, match_list[1], max_equal + 1);
 	match_list[0] = retstr;

Modified: trunk/main/config.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/config.c?view=diff&rev=366917&r1=366916&r2=366917
==============================================================================
--- trunk/main/config.c (original)
+++ trunk/main/config.c Fri May 18 09:43:44 2012
@@ -1491,6 +1491,8 @@
 
 			if (unchanged) {
 				AST_LIST_UNLOCK(&cfmtime_head);
+				ast_free(comment_buffer);
+				ast_free(lline_buffer);
 				return CONFIG_STATUS_FILEUNCHANGED;
 			}
 		}
@@ -1643,7 +1645,7 @@
 		}
 #endif
 
-	if (cfg && cfg != CONFIG_STATUS_FILEUNCHANGED && cfg != CONFIG_STATUS_FILEINVALID && cfg->include_level == 1 && ast_test_flag(&flags, CONFIG_FLAG_WITHCOMMENTS)) {
+	if (ast_test_flag(&flags, CONFIG_FLAG_WITHCOMMENTS)) {
 		ast_free(comment_buffer);
 		ast_free(lline_buffer);
 		comment_buffer = NULL;

Modified: trunk/main/data.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/data.c?view=diff&rev=366917&r1=366916&r2=366917
==============================================================================
--- trunk/main/data.c (original)
+++ trunk/main/data.c Fri May 18 09:43:44 2012
@@ -1042,6 +1042,7 @@
 	cmp_type = child->cmp_type;
 
 	if (sscanf(child->value, "%p", &node_ptr) <= 0) {
+		ao2_ref(child, -1);
 		return 1;
 	}
 
@@ -2186,6 +2187,7 @@
 
 	doc = ast_xml_new();
 	if (!doc) {
+		ast_data_free(res);
 		return NULL;
 	}
 

Modified: trunk/main/editline/readline.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/editline/readline.c?view=diff&rev=366917&r1=366916&r2=366917
==============================================================================
--- trunk/main/editline/readline.c (original)
+++ trunk/main/editline/readline.c Fri May 18 09:43:44 2012
@@ -549,6 +549,7 @@
 						from = strdup(search);
 					else {
 						from = NULL;
+						free(line);
 						return (-1);
 					}
 				}
@@ -609,8 +610,13 @@
 		end = max - ((end < -1) ? 1 : 0);
 
 	/* check boundaries ... */
-	if (start > max || end > max || start > end)
+	if (start > max || end > max || start > end) {
+		for (i = 0; i <= max; i++) {
+			free(arr[i]);
+		}
+		free(arr), arr = (char **) NULL;
 		return (-1);
+	}
 
 	for (i = 0; i <= max; i++) {
 		char *temp;

Modified: trunk/main/editline/term.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/editline/term.c?view=diff&rev=366917&r1=366916&r2=366917
==============================================================================
--- trunk/main/editline/term.c (original)
+++ trunk/main/editline/term.c Fri May 18 09:43:44 2012
@@ -472,7 +472,7 @@
 private int
 term_alloc_display(EditLine *el)
 {
-	int i;
+	int i, j;
 	char **b;
 	coord_t *c = &el->el_term.t_size;
 
@@ -481,8 +481,13 @@
 		return (-1);
 	for (i = 0; i < c->v; i++) {
 		b[i] = (char *) el_malloc((size_t) (sizeof(char) * (c->h + 1)));
-		if (b[i] == NULL)
+		if (b[i] == NULL) {
+			for (j = 0; j < i; j++) {
+				el_free(b[j]);
+			}
+			el_free(b);
 			return (-1);
+		}
 	}
 	b[c->v] = NULL;
 	el->el_display = b;
@@ -492,8 +497,13 @@
 		return (-1);
 	for (i = 0; i < c->v; i++) {
 		b[i] = (char *) el_malloc((size_t) (sizeof(char) * (c->h + 1)));
-		if (b[i] == NULL)
+		if (b[i] == NULL) {
+			for (j = 0; j < i; j++) {
+				el_free(b[j]);
+			}
+			el_free(b);
 			return (-1);
+		}
 	}
 	b[c->v] = NULL;
 	el->el_vdisplay = b;

Modified: trunk/main/editline/tokenizer.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/editline/tokenizer.c?view=diff&rev=366917&r1=366916&r2=366917
==============================================================================
--- trunk/main/editline/tokenizer.c (original)
+++ trunk/main/editline/tokenizer.c Fri May 18 09:43:44 2012
@@ -113,12 +113,17 @@
 	tok->argc = 0;
 	tok->amax = AINCR;
 	tok->argv = (char **) tok_malloc(sizeof(char *) * tok->amax);
-	if (tok->argv == NULL)
+	if (tok->argv == NULL) {
+		tok_free(tok);
 		return (NULL);
+	}
 	tok->argv[0] = NULL;
 	tok->wspace = (char *) tok_malloc(WINCR);
-	if (tok->wspace == NULL)
+	if (tok->wspace == NULL) {
+		tok_free(tok->argv);
+		tok_free(tok);
 		return (NULL);
+	}
 	tok->wmax = tok->wspace + WINCR;
 	tok->wstart = tok->wspace;
 	tok->wptr = tok->wspace;

Modified: trunk/main/enum.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/enum.c?view=diff&rev=366917&r1=366916&r2=366917
==============================================================================
--- trunk/main/enum.c (original)
+++ trunk/main/enum.c Fri May 18 09:43:44 2012
@@ -790,6 +790,7 @@
 
 		if (sdl > strlen(number)) {	/* Number too short for this sdl? */
 			ast_log(LOG_WARNING, "I-ENUM: subdomain location %d behind number %s\n", sdl, number);
+			ast_free(context);
 			return 0;
 		}
 		ast_copy_string(left, number + sdl, sizeof(left));
@@ -802,6 +803,7 @@
 		/* check the space we need for middle */
 		if ((sdl * 2 + strlen(middle) + 2) > sizeof(middle)) {
 			ast_log(LOG_WARNING, "ast_get_enum: not enough space for I-ENUM rewrite.\n");
+			ast_free(context);
 			return -1;
 		}
 
@@ -819,6 +821,7 @@
 
 	if (strlen(left) * 2 + 2 > sizeof(domain)) {
 		ast_log(LOG_WARNING, "string to long in ast_get_enum\n");
+		ast_free(context);
 		return -1;
 	}
 

Modified: trunk/main/features.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/features.c?view=diff&rev=366917&r1=366916&r2=366917
==============================================================================
--- trunk/main/features.c (original)
+++ trunk/main/features.c Fri May 18 09:43:44 2012
@@ -6044,6 +6044,7 @@
 	} else {
 		ast_log(LOG_NOTICE, "Invalid 'ActivateOn' specification for feature '%s',"
 			" must be 'self', or 'peer'\n", var->name);
+		ast_free(feature);
 		return;
 	}
 
@@ -6058,6 +6059,7 @@
 	} else {
 		ast_log(LOG_NOTICE, "Invalid 'ActivatedBy' specification for feature '%s',"
 			" must be 'caller', or 'callee', or 'both'\n", var->name);
+		ast_free(feature);
 		return;
 	}
 

Modified: trunk/main/netsock2.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/netsock2.c?view=diff&rev=366917&r1=366916&r2=366917
==============================================================================
--- trunk/main/netsock2.c (original)
+++ trunk/main/netsock2.c Fri May 18 09:43:44 2012
@@ -270,6 +270,10 @@
 		res_cnt++;
 	}
 
+	if (res_cnt == 0) {
+		goto cleanup;
+	}
+
 	if ((*addrs = ast_malloc(res_cnt * sizeof(struct ast_sockaddr))) == NULL) {
 		res_cnt = 0;
 		goto cleanup;

Modified: trunk/main/pbx.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/pbx.c?view=diff&rev=366917&r1=366916&r2=366917
==============================================================================
--- trunk/main/pbx.c (original)
+++ trunk/main/pbx.c Fri May 18 09:43:44 2012
@@ -7511,6 +7511,8 @@
 
 				if (!new) {
 					ast_log(LOG_ERROR,"Could not allocate a new context for %s in merge_and_delete! Danger!\n", context->name);
+					ast_hashtab_end_traversal(prio_iter);
+					ast_hashtab_end_traversal(exten_iter);
 					return; /* no sense continuing. */
 				}
 				/* we will not replace existing entries in the new context with stuff from the old context.
@@ -8236,6 +8238,7 @@
 		if (!strcasecmp(ignorepatc->pattern, value)) {
 			/* Already there */
 			ast_unlock_context(con);
+			ast_free(ignorepat);
 			errno = EEXIST;
 			return -1;
 		}

Modified: trunk/main/xmldoc.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/xmldoc.c?view=diff&rev=366917&r1=366916&r2=366917
==============================================================================
--- trunk/main/xmldoc.c (original)
+++ trunk/main/xmldoc.c Fri May 18 09:43:44 2012
@@ -1666,6 +1666,7 @@
 		ast_str_append(buffer, 0, "\n");
 		ast_xml_free_attr(optname);
 		ast_xml_free_attr(hasparams);
+		ast_free(optionsyntax);
 	}
 }
 
@@ -1740,12 +1741,14 @@
 	char *retstr = NULL;
 
 	if (ast_strlen_zero(type) || ast_strlen_zero(name)) {
+		ast_free(ret);
 		return NULL;
 	}
 
 	node = xmldoc_get_node(type, name, module, documentation_language);
 
 	if (!node || !ast_xml_node_get_children(node)) {
+		ast_free(ret);
 		return NULL;
 	}
 
@@ -1758,6 +1761,7 @@
 
 	if (!node || !ast_xml_node_get_children(node)) {
 		/* We couldn't find the syntax node. */
+		ast_free(ret);
 		return NULL;
 	}
 

Modified: trunk/res/res_calendar.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_calendar.c?view=diff&rev=366917&r1=366916&r2=366917
==============================================================================
--- trunk/res/res_calendar.c (original)
+++ trunk/res/res_calendar.c Fri May 18 09:43:44 2012
@@ -374,6 +374,7 @@
 
 static enum ast_device_state calendarstate(const char *data)
 {
+	enum ast_device_state state;
 	struct ast_calendar *cal;
 
 	if (ast_strlen_zero(data) || (!(cal = find_calendar(data)))) {
@@ -381,10 +382,13 @@
 	}
 
 	if (cal->tech->is_busy) {
-		return cal->tech->is_busy(cal) ? AST_DEVICE_INUSE : AST_DEVICE_NOT_INUSE;
-	}
-
-	return calendar_is_busy(cal) ? AST_DEVICE_INUSE : AST_DEVICE_NOT_INUSE;
+		state = cal->tech->is_busy(cal) ? AST_DEVICE_INUSE : AST_DEVICE_NOT_INUSE;
+	} else {
+		state = calendar_is_busy(cal) ? AST_DEVICE_INUSE : AST_DEVICE_NOT_INUSE;
+	}
+
+	cal = unref_calendar(cal);
+	return state;
 }
 
 static struct ast_calendar *build_calendar(struct ast_config *cfg, const char *cat, const struct ast_calendar_tech *tech)
@@ -1060,6 +1064,7 @@
 	}
 
 	strcpy(buf, calendar_is_busy(cal) ? "1" : "0");
+	cal = unref_calendar(cal);
 
 	return 0;
 }
@@ -1214,6 +1219,8 @@
 			ast_debug(10, "%s (%ld - %ld) overlapped with (%ld - %ld)\n", event->summary, (long) event->start, (long) event->end, (long) start, (long) end);
 			if (add_event_to_list(events, event, start, end) < 0) {
 				event = ast_calendar_unref_event(event);
+				cal = unref_calendar(cal);
+				ao2_ref(events, -1);
 				ao2_iterator_destroy(&i);
 				return -1;
 			}
@@ -1231,6 +1238,8 @@
 
 	if (!(eventlist_datastore = ast_datastore_alloc(&eventlist_datastore_info, buf))) {
 		ast_log(LOG_ERROR, "Could not allocate datastore!\n");
+		cal = unref_calendar(cal);
+		ao2_ref(events, -1);
 		return -1;
 	}
 
@@ -1241,6 +1250,7 @@
 	ast_channel_datastore_add(chan, eventlist_datastore);
 	ast_channel_unlock(chan);
 
+	cal = unref_calendar(cal);
 	return 0;
 }
 

Modified: trunk/res/res_calendar_caldav.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_calendar_caldav.c?view=diff&rev=366917&r1=366916&r2=366917
==============================================================================
--- trunk/res/res_calendar_caldav.c (original)
+++ trunk/res/res_calendar_caldav.c Fri May 18 09:43:44 2012
@@ -188,9 +188,8 @@
 		return -1;
 	}
 	if (!(body = ast_str_create(512)) ||
-		!(subdir = ast_str_create(32)) ||
-		!(response = ast_str_create(512))) {
-		ast_log(LOG_ERROR, "Could not allocate memory for request and response!\n");
+		!(subdir = ast_str_create(32))) {
+		ast_log(LOG_ERROR, "Could not allocate memory for request!\n");
 		goto write_cleanup;
 	}
 
@@ -417,10 +416,12 @@
 			return;
 		}
 		data = icalproperty_get_attendee(prop);
-		if (!ast_strlen_zero(data)) {
-			attendee->data = ast_strdup(data);;
-			AST_LIST_INSERT_TAIL(&event->attendees, attendee, next);
+		if (ast_strlen_zero(data)) {
+			ast_free(attendee);
+			continue;
 		}
+		attendee->data = ast_strdup(data);
+		AST_LIST_INSERT_TAIL(&event->attendees, attendee, next);
 	}
 
 

Modified: trunk/res/res_calendar_exchange.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_calendar_exchange.c?view=diff&rev=366917&r1=366916&r2=366917
==============================================================================
--- trunk/res/res_calendar_exchange.c (original)
+++ trunk/res/res_calendar_exchange.c Fri May 18 09:43:44 2012
@@ -433,9 +433,8 @@
 		return -1;
 	}
 	if (!(body = ast_str_create(512)) ||
-		!(subdir = ast_str_create(32)) ||
-		!(response = ast_str_create(512))) {
-		ast_log(LOG_ERROR, "Could not allocate memory for request and response!\n");
+		!(subdir = ast_str_create(32))) {
+		ast_log(LOG_ERROR, "Could not allocate memory for request!\n");
 		goto write_cleanup;
 	}
 

Modified: trunk/res/res_calendar_icalendar.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_calendar_icalendar.c?view=diff&rev=366917&r1=366916&r2=366917
==============================================================================
--- trunk/res/res_calendar_icalendar.c (original)
+++ trunk/res/res_calendar_icalendar.c Fri May 18 09:43:44 2012
@@ -261,10 +261,12 @@
 			return;
 		}
 		data = icalproperty_get_attendee(prop);
-		if (!ast_strlen_zero(data)) {
-			attendee->data = ast_strdup(data);;
-			AST_LIST_INSERT_TAIL(&event->attendees, attendee, next);
-		}
+		if (ast_strlen_zero(data)) {
+			ast_free(attendee);
+			continue;
+		}
+		attendee->data = ast_strdup(data);;
+		AST_LIST_INSERT_TAIL(&event->attendees, attendee, next);
 	}
 
 

Modified: trunk/res/res_jabber.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_jabber.c?view=diff&rev=366917&r1=366916&r2=366917
==============================================================================
--- trunk/res/res_jabber.c (original)
+++ trunk/res/res_jabber.c Fri May 18 09:43:44 2012
@@ -2292,6 +2292,7 @@
 		/* insert will furtherly be added to message list */
 		insert->from = ast_strdup(pak->from->full);
 		if (!insert->from) {
+			ast_free(insert);
 			ast_log(LOG_ERROR, "Memory allocation failure\n");
 			return;
 		}

Modified: trunk/res/res_rtp_asterisk.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_rtp_asterisk.c?view=diff&rev=366917&r1=366916&r2=366917
==============================================================================
--- trunk/res/res_rtp_asterisk.c (original)
+++ trunk/res/res_rtp_asterisk.c Fri May 18 09:43:44 2012
@@ -566,6 +566,8 @@
 		/* See if we ran out of ports or if the bind actually failed because of something other than the address being in use */
 		if (x == startplace || errno != EADDRINUSE) {
 			ast_log(LOG_ERROR, "Oh dear... we couldn't allocate a port for RTP instance '%p'\n", instance);
+			close(rtp->s);
+			ast_free(rtp);
 			return -1;
 		}
 	}

Modified: trunk/res/res_srtp.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_srtp.c?view=diff&rev=366917&r1=366916&r2=366917
==============================================================================
--- trunk/res/res_srtp.c (original)
+++ trunk/res/res_srtp.c Fri May 18 09:43:44 2012
@@ -433,12 +433,14 @@
 	if (!(temp = res_srtp_new())) {
 		return -1;
 	}
-
+	ast_module_ref(ast_module_info->self);
+
+	/* Any failures after this point can use ast_srtp_destroy to destroy the instance */
 	if (srtp_create(&temp->session, &policy->sp) != err_status_ok) {
-		return -1;
-	}
-
-	ast_module_ref(ast_module_info->self);
+		ast_srtp_destroy(temp);
+		return -1;
+	}
+
 	temp->rtp = rtp;
 	*srtp = temp;
 




More information about the asterisk-commits mailing list