]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
config.c: Fix off-nominal reference leak.
authorSean Bright <sean@seanbright.com>
Tue, 7 Jan 2025 16:34:04 +0000 (11:34 -0500)
committerasterisk-org-access-app[bot] <120671045+asterisk-org-access-app[bot]@users.noreply.github.com>
Wed, 8 Jan 2025 15:41:47 +0000 (15:41 +0000)
This was identified and fixed by @Allan-N in #918 but it is an
important fix in its own right.

The fix here is slightly different than Allan's in that we just move
the initialization of the problematic AO2 container to where it is
first used.

Fixes #1046

main/config.c

index 4f575046eed25908d0a395fb8e1abbccc643815c..251c33be19bb5a8f3c96deb3105b94c4bcedd6c9 100644 (file)
@@ -2749,13 +2749,6 @@ int ast_config_text_file_save2(const char *configfile, const struct ast_config *
        struct ao2_container *fileset;
        struct inclfile *fi;
 
-       fileset = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, 1023,
-               hash_string, NULL, hashtab_compare_strings);
-       if (!fileset) {
-               /* Container creation failed. */
-               return -1;
-       }
-
        /* Check all the files for write access before attempting to modify any of them */
        for (incl = cfg->includes; incl; incl = incl->next) {
                /* reset all the output flags in case this isn't our first time saving this data */
@@ -2777,6 +2770,13 @@ int ast_config_text_file_save2(const char *configfile, const struct ast_config *
                return -1;
        }
 
+       fileset = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, 1023,
+               hash_string, NULL, hashtab_compare_strings);
+       if (!fileset) {
+               /* Container creation failed. */
+               return -1;
+       }
+
        /* Now that we know we have write access to all files, it's safe to start truncating them */
 
        /* go thru all the inclusions and make sure all the files involved (configfile plus all its inclusions)