Fix some file descriptor leaks 41/245141/1
authorMichal Bloch <m.bloch@samsung.com>
Fri, 2 Oct 2020 17:04:45 +0000 (19:04 +0200)
committerMichal Bloch <m.bloch@samsung.com>
Fri, 2 Oct 2020 17:09:54 +0000 (19:09 +0200)
Change-Id: I1bb8cc2580ca208cc8387a84528d9a60e6909cd3

src/crash-json2info/crash-json2info.c
src/crash-stack/crash-stack.c

index 213a316..b761ada 100644 (file)
@@ -81,6 +81,8 @@ int main(int argc, char *argv[])
                switch(c) {
                case 'o':
                case OPT_OUTPUT_FILE:
+                       if (fp_output != stdout)
+                               fclose(fp_output);
                        fp_output = fopen(optarg, "w");
                        break;
                case 'h':
index 48db99d..16b0e5b 100644 (file)
@@ -633,9 +633,13 @@ int main(int argc, char **argv)
                        signo = atoi(optarg);
                        break;
                case OPT_OUTPUTFILE:
+                       if (outputfile)
+                               fclose(outputfile);
                        outputfile = fopen(optarg, "w");
                        break;
                case OPT_JSONOUTPUTFILE:
+                       if (jsonoutputfile)
+                               fclose(jsonoutputfile);
                        jsonoutputfile = fopen(optarg, "w");
                        break;
                case OPT_PRSTATUS_FD: