From: Andre Noll Date: Fri, 13 Jan 2012 22:54:08 +0000 (+0100) Subject: audioc: Fix memory leak in configfile_exists(). X-Git-Tag: v0.4.10~8^2~1 X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=commitdiff_plain;h=d4b040af5e31260dbf71f4547484179f32be4746;hp=d73a140ae7f77a18f858a66d1a354d106088c6ca;ds=sidebyside audioc: Fix memory leak in configfile_exists(). In case the config file does not exist, the function returns NULL without freeing the config_file buffer. This patch also makes config_file non-static. As configfile_exists() is called at most once, it is pointless to have a static variable there. The condition "if (!config_file)" is always true, so we can get rid of the conditional alltogether. --- diff --git a/audioc.c b/audioc.c index 64152ce0..0c0eea47 100644 --- a/audioc.c +++ b/audioc.c @@ -253,16 +253,15 @@ __noreturn static void print_completions(void) static char *configfile_exists(void) { - static char *config_file; + char *config_file; struct stat statbuf; + char *home = para_homedir(); - if (!config_file) { - char *home = para_homedir(); - config_file = make_message("%s/.paraslash/audioc.conf", home); - free(home); - } + config_file = make_message("%s/.paraslash/audioc.conf", home); + free(home); if (!stat(config_file, &statbuf)) return config_file; + free(config_file); return NULL; }