[Olsr-dev] [PATCH v1 1/1] conf: clean up interface names on config file read failure

Ferry Huberts (spam-protected)
Thu Oct 15 15:09:03 CEST 2015


From: Ferry Huberts <(spam-protected)>

==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 <(spam-protected)>
---
 src/cfgparser/olsrd_conf.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/src/cfgparser/olsrd_conf.c b/src/cfgparser/olsrd_conf.c
index 37a1cb6..c68477f 100644
--- a/src/cfgparser/olsrd_conf.c
+++ b/src/cfgparser/olsrd_conf.c
@@ -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;
   }
 
-- 
2.5.0




More information about the Olsr-dev mailing list