chiark / gitweb /
readahead: make sure to close pack file before exiting, to be valgrind clean
authorLennart Poettering <lennart@poettering.net>
Thu, 21 Jun 2012 22:03:25 +0000 (00:03 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 21 Jun 2012 22:03:25 +0000 (00:03 +0200)
src/readahead/readahead-analyze.c
src/readahead/readahead-replay.c

index 42bf9dbac97673d21c6703dec804ce4ad810cf4c..75f85b46e068543e335bbd16412e09170396a95b 100644 (file)
 
 int main_analyze(const char *pack_path)
 {
-        char line[1024];
+        char line[LINE_MAX];
         char path[PATH_MAX];
         FILE *pack;
         int a;
         int missing = 0;
         off_t size;
-        long tsize = 0;
+        off_t tsize = 0;
         uint64_t inode;
         uint32_t b;
         uint32_t c;
@@ -52,22 +52,24 @@ int main_analyze(const char *pack_path)
         pack = fopen(pack_path, "re");
         if (!pack) {
                 log_error("Pack file missing.");
-                return EXIT_FAILURE;
+                goto fail;
         }
 
         if (!fgets(line, sizeof(line), pack)) {
                 log_error("Pack file corrupt.");
-                return EXIT_FAILURE;
+                goto fail;
         }
 
-        if (!strstr(line, READAHEAD_PACK_FILE_VERSION)) {
+        char_array_0(line);
+
+        if (!endswith(line, READAHEAD_PACK_FILE_VERSION)) {
                 log_error("Pack file version incompatible with this parser.");
-                return EXIT_FAILURE;
+                goto fail;
         }
 
         if ((a = getc(pack)) == EOF) {
                 log_error("Pack file corrupt.");
-                return EXIT_FAILURE;
+                goto fail;
         }
 
         fprintf(stdout, "   pct  sections     size: path\n");
@@ -84,14 +86,14 @@ int main_analyze(const char *pack_path)
 
                 if (fread(&inode, sizeof(inode), 1, pack) != 1) {
                         log_error("Pack file corrupt.");
-                        return EXIT_FAILURE;
+                        goto fail;
                 }
 
                 while (true) {
                         if (fread(&b, sizeof(b), 1, pack) != 1  ||
                             fread(&c, sizeof(c), 1, pack) != 1) {
                                 log_error("Pack file corrupt.");
-                                return EXIT_FAILURE;
+                                goto fail;
                         }
                         if ((b == 0) && (c == 0))
                                 break;
@@ -128,10 +130,17 @@ int main_analyze(const char *pack_path)
 
         }
 
+        fclose(pack);
+
         fprintf(stdout, "\nHOST:    %s", line);
         fprintf(stdout, "TYPE:    %c\n", a);
         fprintf(stdout, "MISSING: %d\n", missing);
         fprintf(stdout, "TOTAL:   %ld\n", tsize);
 
         return EXIT_SUCCESS;
+
+
+fail:
+        fclose(pack);
+        return EXIT_FAILURE;
 }
index 6e6db601d45a101356ee9cadb907104810ba184d..7bd079aae591c5459617313401fd102ae282fcca 100644 (file)
@@ -155,7 +155,8 @@ static int replay(const char *root) {
                 goto finish;
         }
 
-        if ((!(pack = fopen(pack_fn, "re")))) {
+        pack = fopen(pack_fn, "re");
+        if (!pack) {
                 if (errno == ENOENT)
                         log_debug("No pack file found.");
                 else {