diff options
author | Matthew Jordan <mjordan@digium.com> | 2012-05-18 14:43:44 +0000 |
---|---|---|
committer | Matthew Jordan <mjordan@digium.com> | 2012-05-18 14:43:44 +0000 |
commit | 7b51320642349100921af1308cb277c21d4fe18c (patch) | |
tree | 07841f22e8cb74ee5a457599b297ab58a3052e80 /apps/app_voicemail.c | |
parent | 6fc8e9928dbb0775bf5affdde5ccc0597fa105e1 (diff) |
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
Diffstat (limited to 'apps/app_voicemail.c')
-rw-r--r-- | apps/app_voicemail.c | 47 |
1 files changed, 31 insertions, 16 deletions
diff --git a/apps/app_voicemail.c b/apps/app_voicemail.c index 7e75ea9a9..eec08a484 100644 --- a/apps/app_voicemail.c +++ b/apps/app_voicemail.c @@ -11728,16 +11728,22 @@ static int handle_subscribe(void *datap) 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) + + if (!uniqueid) { + ast_log(LOG_ERROR, "Unable to allocate memory for uniqueid\n"); return; + } - if (ast_event_get_ie_uint(event, AST_EVENT_IE_EVENTTYPE) != AST_EVENT_MWI) + if (ast_event_get_type(event) != AST_EVENT_UNSUB) { + ast_free(uniqueid); return; + } - if (!uniqueid) { - ast_log(LOG_ERROR, "Unable to allocate memory for uniqueid\n"); + 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 @@ static void read_password_from_file(const char *secretfn, char *password, int pa 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 @@ static int write_password_to_file(const char *secretfn, const char *password) { struct ast_config *conf; struct ast_category *cat; struct ast_variable *var; + int res = -1; - if (!(conf=ast_config_new())) { + if (!(conf = ast_config_new())) { ast_log(LOG_ERROR, "Error creating new config structure\n"); - return -1; + return res; } - if (!(cat=ast_category_new("general","",1))) { + if (!(cat = ast_category_new("general", "", 1))) { ast_log(LOG_ERROR, "Error creating new category structure\n"); - return -1; + ast_config_destroy(conf); + return res; } - if (!(var=ast_variable_new("password",password,""))) { + if (!(var = ast_variable_new("password", password, ""))) { ast_log(LOG_ERROR, "Error creating new variable structure\n"); - return -1; + 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")) { + 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) |