conf: clean up interface names on config file read failure
authorFerry Huberts <ferry.huberts@pelagic.nl>
Thu, 15 Oct 2015 12:41:59 +0000 (14:41 +0200)
committerFerry Huberts <ferry.huberts@pelagic.nl>
Sun, 18 Oct 2015 18:04:48 +0000 (20:04 +0200)
==12076==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 7 byte(s) in 1 object(s) allocated from:
    #0 0x499bba in __interceptor_malloc (/home/ferry/vcs/nbs/nbsolsrd/olsrd+0x499bba)
    #1 0x5784cd in get_string_token src/cfgparser/oscan.lex:92
    #2 0x578ef7 in yylex src/cfgparser/oscan.lex:185
    #3 0x5699c4 in yyparse src/cfgparser/oparse.c:1686
    #4 0x55e322 in olsrd_parse_cnf src/cfgparser/olsrd_conf.c:158
    #5 0x4edf56 in olsrmain_load_config src/main.c:281
    #6 0x4ee5e6 in main src/main.c:386
    #7 0x7fd24079757f in __libc_start_main (/lib64/libc.so.6+0x2057f)

SUMMARY: AddressSanitizer: 7 byte(s) leaked in 1 allocation(s).

Signed-off-by: Ferry Huberts <ferry.huberts@pelagic.nl>
src/cfgparser/olsrd_conf.c

index 37a1cb6..c68477f 100644 (file)
@@ -158,6 +158,13 @@ olsrd_parse_cnf(const char *filename)
   rc = yyparse();
   fclose(yyin);
   if (rc != 0) {
+    /* Interface names that were parsed successfully are not cleaned up. */
+    struct olsr_if* b = olsr_cnf->interfaces;
+    while (b) {
+      free(b->name);
+      b->name = NULL;
+      b = b->next;
+    }
     return -1;
   }