conf: Memory-leak in DetectAddressTestConfVars

There is a memory-leak in DetectAddressTestConfVars. If the programm takes the "goto error"-path, the pointers gh and ghn will not be freed. This commit fixes bug #2345. Here is the ASAN-output:

=================================================================
ERROR: LeakSanitizer: detected memory leaks

Direct leak of 24 byte(s) in 1 object(s) allocated from:
0 0x7f4347cb1d28 in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.3+0xc1d28)
1 0x55fe1fc8dcfc in DetectAddressHeadInit /root/suricata-1/src/detect-engine-address.c:1534
2 0x55fe1fc8c50a in DetectAddressTestConfVars /root/suricata-1/src/detect-engine-address.c:1306
3 0x55fe1ff356bd in PostConfLoadedSetup /root/suricata-1/src/suricata.c:2696
4 0x55fe1ff365eb in main /root/suricata-1/src/suricata.c:2884
5 0x7f43443892b0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x202b0)

Direct leak of 24 byte(s) in 1 object(s) allocated from:
0 0x7f4347cb1d28 in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.3+0xc1d28)
1 0x55fe1fc8dcfc in DetectAddressHeadInit /root/suricata-1/src/detect-engine-address.c:1534
2 0x55fe1fc8c524 in DetectAddressTestConfVars /root/suricata-1/src/detect-engine-address.c:1310
3 0x55fe1ff356bd in PostConfLoadedSetup /root/suricata-1/src/suricata.c:2696
4 0x55fe1ff365eb in main /root/suricata-1/src/suricata.c:2884
5 0x7f43443892b0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x202b0)

SUMMARY: AddressSanitizer: 48 byte(s) leaked in 2 allocation(s).
pull/3078/head
Wolfgang Hotwagner 7 years ago committed by Victor Julien
parent 99bf99c529
commit cfd56f5ef7

@ -1299,15 +1299,18 @@ int DetectAddressTestConfVars(void)
return 0;
}
DetectAddressHead *gh = NULL;
DetectAddressHead *ghn = NULL;
ConfNode *seq_node;
TAILQ_FOREACH(seq_node, &address_vars_node->head, next) {
SCLogDebug("Testing %s - %s", seq_node->name, seq_node->val);
DetectAddressHead *gh = DetectAddressHeadInit();
gh = DetectAddressHeadInit();
if (gh == NULL) {
goto error;
}
DetectAddressHead *ghn = DetectAddressHeadInit();
ghn = DetectAddressHeadInit();
if (ghn == NULL) {
goto error;
}
@ -1340,14 +1343,22 @@ int DetectAddressTestConfVars(void)
goto error;
}
if (gh != NULL)
if (gh != NULL) {
DetectAddressHeadFree(gh);
if (ghn != NULL)
gh = NULL;
}
if (ghn != NULL) {
DetectAddressHeadFree(ghn);
ghn = NULL;
}
}
return 0;
error:
if (gh != NULL)
DetectAddressHeadFree(gh);
if (ghn != NULL)
DetectAddressHeadFree(ghn);
return -1;
}

Loading…
Cancel
Save