File: Fix-use-after-free.diff

package info (click to toggle)
readstat 1.1.9-4
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 2,172 kB
  • sloc: ansic: 32,268; makefile: 377; sh: 1
file content (30 lines) | stat: -rw-r--r-- 748 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
Author: Stefan Gerlach <stefan.gerlach@uni-konstanz.de>
Description: Fix use after free
Forwarded: https://github.com/WizardMac/ReadStat/pull/298

--- a/src/bin/readstat.c
+++ b/src/bin/readstat.c
@@ -397,8 +397,6 @@ cleanup:
         module->finish(rs_ctx->module_ctx);
     }
 
-    free(rs_ctx);
-
     if (error != READSTAT_OK) {
         if (file_exists) {
             fprintf(stderr, "Error opening %s: File exists (Use -f to overwrite)\n", output_filename);
@@ -406,9 +404,14 @@ cleanup:
             fprintf(stderr, "Error processing %s: %s\n", rs_ctx->error_filename, readstat_error_message(error));
             unlink(output_filename);
         }
+
+	free(rs_ctx);
+
         return 1;
     }
 
+    free(rs_ctx);
+
     return 0;
 }