]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
various: cleanup issues found during leak hunt
authorScott Griepentrog <sgriepentrog@digium.com>
Fri, 6 Feb 2015 21:26:12 +0000 (21:26 +0000)
committerScott Griepentrog <sgriepentrog@digium.com>
Fri, 6 Feb 2015 21:26:12 +0000 (21:26 +0000)
In this collection of small patches to prevent
Valgrind errors are: fixes for reference leaks
in config hooks, evaluating a parameter beyond
bounds, and accessing a structure after a lock
where it could have been already free'd.

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

git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/13@431583 65c4cc65-6c06-0410-ace0-fbb531ad65f3

main/config.c
main/utils.c
res/res_pjsip.c

index 0aa6bbefcf197befdc8df87688cbbccb36ede47f..7e5141398f4b15cf0351f05bbf64d6b124e026f8 100644 (file)
@@ -3821,6 +3821,9 @@ static void config_shutdown(void)
        AST_LIST_UNLOCK(&cfmtime_head);
 
        ast_cli_unregister_multiple(cli_config, ARRAY_LEN(cli_config));
+
+       ao2_cleanup(cfg_hooks);
+       cfg_hooks = NULL;
 }
 
 int register_config_cli(void)
@@ -3909,5 +3912,6 @@ int ast_config_hook_register(const char *name,
        hook->module = ast_strdup(module);
 
        ao2_link(cfg_hooks, hook);
+       ao2_ref(hook, -1);
        return 0;
 }
index 7032631f8afc62c96fcbd9e4f3ad092acce0b36c..578a01e2652514c0a5a7a73661e300adc4619d9a 100644 (file)
@@ -1856,7 +1856,7 @@ void ast_join_delim(char *s, size_t len, const char * const w[], unsigned int si
        /* Join words into a string */
        if (!s)
                return;
-       for (x = 0; ofs < len && w[x] && x < size; x++) {
+       for (x = 0; ofs < len && x < size && w[x] ; x++) {
                if (x > 0)
                        s[ofs++] = delim;
                for (src = w[x]; *src && ofs < len; src++)
index fd470b7198c86f12cddd22b85f00c53be74b63c1..4427c4ecfef9ce03a5819d1eef9acf3d2d2bf265 100644 (file)
@@ -2965,13 +2965,16 @@ struct sync_task_data {
 static int sync_task(void *data)
 {
        struct sync_task_data *std = data;
+       int ret;
+
        std->fail = std->task(std->task_data);
 
        ast_mutex_lock(&std->lock);
        std->complete = 1;
        ast_cond_signal(&std->cond);
+       ret = std->fail;
        ast_mutex_unlock(&std->lock);
-       return std->fail;
+       return ret;
 }
 
 int ast_sip_push_task_synchronous(struct ast_taskprocessor *serializer, int (*sip_task)(void *), void *task_data)