From: Sean Bright Date: Tue, 7 Jan 2025 16:34:04 +0000 (-0500) Subject: config.c: Fix off-nominal reference leak. X-Git-Tag: 21.7.0-rc1~25 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=32bf6bbf13c2029b0c8cfd7dca4ba7a026dc5c42;p=thirdparty%2Fasterisk.git config.c: Fix off-nominal reference leak. 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 (cherry picked from commit c7562392b98b8d48f7eb2868442acf553881a563) --- diff --git a/main/config.c b/main/config.c index e3438da6c9..3d7bcbe62f 100644 --- a/main/config.c +++ b/main/config.c @@ -2735,13 +2735,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 */ @@ -2763,6 +2756,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)