From 553f7ec290441dccffec5f63e5f1033bc79c0683 Mon Sep 17 00:00:00 2001 From: Jason Ish Date: Thu, 24 Nov 2016 10:36:27 -0600 Subject: [PATCH] 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). --- src/log-pcap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/log-pcap.c b/src/log-pcap.c index 1d2dba9644..0513c41deb 100644 --- a/src/log-pcap.c +++ b/src/log-pcap.c @@ -612,7 +612,7 @@ static TmEcode PcapLogInitRingBuffer(PcapLogData *pl) PcapFileName *pf = SCCalloc(sizeof(*pf), 1); if (unlikely(pf == NULL)) { - return TM_ECODE_FAILED; + goto fail; } char path[PATH_MAX]; snprintf(path, PATH_MAX - 1, "%s/%s", pattern, entry->d_name);