]> granicus.if.org Git - clang/commitdiff
Fix some memory leaks found by the static analyzer. Thanks to John Smith for running...
authorRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 5 Jul 2012 08:20:49 +0000 (08:20 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 5 Jul 2012 08:20:49 +0000 (08:20 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@159732 91177308-0d34-0410-b5e6-96231b3b80d8

tools/c-index-test/c-index-test.c

index e16be7d185fae3c120724a5d9be0e4f3e98b40d1..b3b5b8447ff0a0450e546f4bcdfeb4f9f261e454 100644 (file)
@@ -157,6 +157,7 @@ int parse_remapped_files(int argc, const char **argv, int start_arg,
               (feof(to_file) ? "EOF" : "error"), semi + 1);
       fclose(to_file);
       free_remapped_files(*unsaved_files, i);
+      free(contents);
       *unsaved_files = 0;
       *num_unsaved_files = 0;
       return -1;
@@ -2281,8 +2282,10 @@ int perform_token_annotation(int argc, const char **argv) {
                                           &second_line, &second_column)))
     return errorCode;
 
-  if (parse_remapped_files(argc, argv, 2, &unsaved_files, &num_unsaved_files))
+  if (parse_remapped_files(argc, argv, 2, &unsaved_files, &num_unsaved_files)) {
+    free(filename);
     return -1;
+  }
 
   CIdx = clang_createIndex(0, 1);
   TU = clang_parseTranslationUnit(CIdx, argv[argc - 1],
@@ -2300,8 +2303,10 @@ int perform_token_annotation(int argc, const char **argv) {
   }
   errorCode = 0;
 
-  if (checkForErrors(TU) != 0)
-    return -1;
+  if (checkForErrors(TU) != 0) {
+    errorCode = -1;
+    goto teardown;
+  }
 
   if (getenv("CINDEXTEST_EDITING")) {
     for (i = 0; i < 5; ++i) {