Browse Source

hashsum: cleanup at exit

Steffen Jaeckel 8 years ago
parent
commit
eb75c894db
1 changed files with 6 additions and 1 deletions
  1. 6 1
      demos/hashsum.c

+ 6 - 1
demos/hashsum.c

@@ -38,6 +38,11 @@
 
 
 static char* hashsum;
 static char* hashsum;
 
 
+static void cleanup(void)
+{
+   free(hashsum);
+}
+
 static void die(int status)
 static void die(int status)
 {
 {
    unsigned long w, x;
    unsigned long w, x;
@@ -53,7 +58,6 @@ static void die(int status)
       }
       }
    }
    }
    if (w != 0) fprintf(o, "\n");
    if (w != 0) fprintf(o, "\n");
-   free(hashsum);
    exit(status);
    exit(status);
 }
 }
 
 
@@ -173,6 +177,7 @@ int main(int argc, char **argv)
    unsigned char hash_buffer[MAXBLOCKSIZE];
    unsigned char hash_buffer[MAXBLOCKSIZE];
 
 
    hashsum = strdup(basename(argv[0]));
    hashsum = strdup(basename(argv[0]));
+   atexit(cleanup);
 
 
    /* You need to register algorithms before using them */
    /* You need to register algorithms before using them */
    register_all_ciphers();
    register_all_ciphers();