From: Boris Tonofa Date: Sat, 14 Jun 2025 08:44:57 +0000 (+0300) Subject: pcap-log: fix memory leak on error paths after SCStrdup(prefix) X-Git-Tag: suricata-8.0.0~64 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=97bfa3b10883610c7675d5b7d99985667b0ed1a1;p=thirdparty%2Fsuricata.git pcap-log: fix memory leak on error paths after SCStrdup(prefix) When PcapLogDataCopy() fails after duplicating pl->prefix, the allocated 'prefix' string was not freed, leading to a leak. Ticket: 7759 --- diff --git a/src/log-pcap.c b/src/log-pcap.c index 0a3ca5e845..c46921b282 100644 --- a/src/log-pcap.c +++ b/src/log-pcap.c @@ -785,6 +785,7 @@ static PcapLogData *PcapLogDataCopy(const PcapLogData *pl) copy_comp->buffer = SCMalloc(copy_comp->buffer_size); if (copy_comp->buffer == NULL) { SCLogError("SCMalloc failed: %s", strerror(errno)); + SCFree(copy->prefix); SCFree(copy->h); SCFree(copy); return NULL; @@ -793,6 +794,7 @@ static PcapLogData *PcapLogDataCopy(const PcapLogData *pl) if (copy_comp->pcap_buf == NULL) { SCLogError("SCMalloc failed: %s", strerror(errno)); SCFree(copy_comp->buffer); + SCFree(copy->prefix); SCFree(copy->h); SCFree(copy); return NULL; @@ -803,6 +805,7 @@ static PcapLogData *PcapLogDataCopy(const PcapLogData *pl) SCLogError("SCFmemopen failed: %s", strerror(errno)); SCFree(copy_comp->buffer); SCFree(copy_comp->pcap_buf); + SCFree(copy->prefix); SCFree(copy->h); SCFree(copy); return NULL; @@ -817,6 +820,7 @@ static PcapLogData *PcapLogDataCopy(const PcapLogData *pl) fclose(copy_comp->pcap_buf_wrapper); SCFree(copy_comp->buffer); SCFree(copy_comp->pcap_buf); + SCFree(copy->prefix); SCFree(copy->h); SCFree(copy); return NULL;