mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-12 15:45:18 +00:00
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 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@366917 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -549,6 +549,7 @@ _history_expand_command(const char *command, size_t cmdlen, char **result)
|
||||
from = strdup(search);
|
||||
else {
|
||||
from = NULL;
|
||||
free(line);
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
@@ -609,8 +610,13 @@ _history_expand_command(const char *command, size_t cmdlen, char **result)
|
||||
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;
|
||||
|
@@ -472,7 +472,7 @@ term_rebuffer_display(EditLine *el)
|
||||
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 @@ term_alloc_display(EditLine *el)
|
||||
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 @@ term_alloc_display(EditLine *el)
|
||||
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;
|
||||
|
@@ -113,12 +113,17 @@ tok_init(const char *ifs)
|
||||
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;
|
||||
|
Reference in New Issue
Block a user