log-pcap.c: fix resource leak found by coverity

Goto the failure label instead of returning which will allow the open
directory to get cleaned up.

Fixes:

*** CID 1394675:  Resource leaks  (RESOURCE_LEAK)
/src/log-pcap.c: 615 in PcapLogInitRingBuffer()
609                  * failure as the file might just not be a pcap log file. */
610                 continue;
611             }
612
613             PcapFileName *pf = SCCalloc(sizeof(*pf), 1);
614             if (unlikely(pf == NULL)) {
>>>     CID 1394675:  Resource leaks  (RESOURCE_LEAK)
>>>     Variable "dir" going out of scope leaks the storage it points to.
615                 return TM_ECODE_FAILED;
616             }
617             char path[PATH_MAX];
618             snprintf(path, PATH_MAX - 1, "%s/%s", pattern, entry->d_name);
619             if ((pf->filename = SCStrdup(path)) == NULL) {
620                 goto fail;

This also means that pf can be NULL which should clear up CID
1394676 (REVERSE_INULL).
pull/2428/head
Jason Ish 9 years ago committed by Victor Julien
parent 0c6c9784a2
commit 553f7ec290

@ -612,7 +612,7 @@ static TmEcode PcapLogInitRingBuffer(PcapLogData *pl)
PcapFileName *pf = SCCalloc(sizeof(*pf), 1); PcapFileName *pf = SCCalloc(sizeof(*pf), 1);
if (unlikely(pf == NULL)) { if (unlikely(pf == NULL)) {
return TM_ECODE_FAILED; goto fail;
} }
char path[PATH_MAX]; char path[PATH_MAX];
snprintf(path, PATH_MAX - 1, "%s/%s", pattern, entry->d_name); snprintf(path, PATH_MAX - 1, "%s/%s", pattern, entry->d_name);

Loading…
Cancel
Save