From de11338de900f5c8840268264bceccbf76cca34f Mon Sep 17 00:00:00 2001 From: Daiki Ueno Date: Thu, 21 Oct 2021 12:19:30 +0200 Subject: [PATCH 1/2] autoopts: makeshell: use ferror before fclose Signed-off-by: Daiki Ueno --- src/libopts/makeshell.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/libopts/makeshell.c b/src/libopts/makeshell.c index b6cb441a..7eb17a1f 100644 --- a/src/libopts/makeshell.c +++ b/src/libopts/makeshell.c @@ -164,9 +164,8 @@ optionParseShell(tOptions * opts) #ifdef HAVE_FCHMOD fchmod(STDOUT_FILENO, 0755); #endif - fclose(stdout); - if (ferror(stdout)) + if (ferror(stdout) || fclose(stdout)) fserr_exit(opts->pzProgName, zwriting, zstdout_name); AGFREE(script_text); -- 2.31.1 From 161097d36b608b615482e42e56a465c9fd740c26 Mon Sep 17 00:00:00 2001 From: Daiki Ueno Date: Thu, 21 Oct 2021 12:43:07 +0200 Subject: [PATCH 2/2] autoopts: load: fix resource leak in error path Signed-off-by: Daiki Ueno --- src/libopts/load.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/libopts/load.c b/src/libopts/load.c index 3f1ce2e6..ad1c4584 100644 --- a/src/libopts/load.c +++ b/src/libopts/load.c @@ -219,8 +219,11 @@ add_prog_path(char * buf, int b_sz, char const * fname, char const * prg_path) * IF we cannot find a directory name separator, * THEN we do not have a path name to our executable file. */ - if (pz == NULL) + if (pz == NULL) { + if (path != prg_path) + AGFREE(path); return false; + } fname += skip; fname_len = strlen(fname) + 1; // + NUL byte @@ -230,8 +233,11 @@ add_prog_path(char * buf, int b_sz, char const * fname, char const * prg_path) * Concatenate the file name to the end of the executable path. * The result may be either a file or a directory. */ - if (dir_len + fname_len > (unsigned)b_sz) + if (dir_len + fname_len > (unsigned)b_sz) { + if (path != prg_path) + AGFREE(path); return false; + } memcpy(buf, path, dir_len); memcpy(buf + dir_len, fname, fname_len); -- 2.31.1