From: Eric Leblond Date: Tue, 31 May 2016 09:21:31 +0000 (+0200) Subject: coverity: fix CID 1362014 X-Git-Tag: suricata-3.1RC1~43 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=291af719c60a198f6875a33bc993a8d8b63451f5;p=thirdparty%2Fsuricata.git coverity: fix CID 1362014 Error handling was not correct regarding ring buffer memory handling. --- diff --git a/src/source-af-packet.c b/src/source-af-packet.c index 8453c1d034..8b065f8c85 100644 --- a/src/source-af-packet.c +++ b/src/source-af-packet.c @@ -1766,7 +1766,7 @@ static int AFPSetupRing(AFPThreadVars *ptv, char *devname) ptv->ring_v3 = SCMalloc(ptv->req3.tp_block_nr * sizeof(*ptv->ring_v3)); if (!ptv->ring_v3) { SCLogError(SC_ERR_MEM_ALLOC, "Unable to malloc ptv ring_v3"); - goto mmap_err; + goto postmmap_err; } for (i = 0; i < ptv->req3.tp_block_nr; ++i) { ptv->ring_v3[i].iov_base = ring_buf + (i * ptv->req3.tp_block_size); @@ -1778,7 +1778,7 @@ static int AFPSetupRing(AFPThreadVars *ptv, char *devname) ptv->ring_v2 = SCMalloc(ptv->req.tp_frame_nr * sizeof (union thdr *)); if (ptv->ring_v2 == NULL) { SCLogError(SC_ERR_MEM_ALLOC, "Unable to allocate frame buf"); - goto mmap_err; + goto postmmap_err; } memset(ptv->ring_v2, 0, ptv->req.tp_frame_nr * sizeof (union thdr *)); /* fill the header ring with proper frame ptr*/ @@ -1798,6 +1798,12 @@ static int AFPSetupRing(AFPThreadVars *ptv, char *devname) return 0; +postmmap_err: + munmap(ring_buf, ring_buflen); + if (ptv->ring_v2) + SCFree(ptv->ring_v2); + if (ptv->ring_v3) + SCFree(ptv->ring_v3); mmap_err: /* Packet mmap does the cleaning when socket is closed */ return AFP_FATAL_ERROR;