From: Victor Julien Date: Fri, 21 Apr 2023 09:33:43 +0000 (+0200) Subject: detect: fix scan-build warnings X-Git-Tag: suricata-7.0.0-rc2~365 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=000064de7de6b908df191ae8bec8414b2208e3f9;p=thirdparty%2Fsuricata.git detect: fix scan-build warnings detect-engine-address.c:1140:17: warning: Use of memory after it is freed [unix.Malloc] r = DetectAddressCmp(ag, ag2); ^~~~~~~~~~~~~~~~~~~~~~~~~ detect-engine-address.c:1169:17: warning: Use of memory after it is freed [unix.Malloc] r = DetectAddressCmp(ag, ag2); ^~~~~~~~~~~~~~~~~~~~~~~~~ 2 warnings generated. detect-engine-port.c:1161:9: warning: Use of memory after it is freed [unix.Malloc] DetectPortPrint(ag2); ^~~~~~~~~~~~~~~~~~~~ 1 warning generated. Bug: #3150. Bug: #3151. --- diff --git a/src/detect-engine-address.c b/src/detect-engine-address.c index 6fb7f25738..8245c9b807 100644 --- a/src/detect-engine-address.c +++ b/src/detect-engine-address.c @@ -1140,14 +1140,12 @@ int DetectAddressMergeNot(DetectAddressHead *gh, DetectAddressHead *ghn) r = DetectAddressCmp(ag, ag2); /* XXX more ??? */ if (r == ADDRESS_EQ || r == ADDRESS_EB) { - if (ag2->prev == NULL) - gh->ipv4_head = ag2->next; - else + if (ag2->prev != NULL) ag2->prev->next = ag2->next; - if (ag2->next != NULL) ag2->next->prev = ag2->prev; - + if (gh->ipv4_head == ag2) + gh->ipv4_head = ag2->next; /* store the next ptr and remove the group */ DetectAddress *next_ag2 = ag2->next; DetectAddressFree(ag2); @@ -1168,14 +1166,12 @@ int DetectAddressMergeNot(DetectAddressHead *gh, DetectAddressHead *ghn) for (ag2 = gh->ipv6_head; ag2 != NULL; ) { r = DetectAddressCmp(ag, ag2); if (r == ADDRESS_EQ || r == ADDRESS_EB) { /* XXX more ??? */ - if (ag2->prev == NULL) - gh->ipv6_head = ag2->next; - else + if (ag2->prev != NULL) ag2->prev->next = ag2->next; - if (ag2->next != NULL) ag2->next->prev = ag2->prev; - + if (gh->ipv6_head == ag2) + gh->ipv6_head = ag2->next; /* store the next ptr and remove the group */ DetectAddress *next_ag2 = ag2->next; DetectAddressFree(ag2); diff --git a/src/detect-engine-port.c b/src/detect-engine-port.c index fe73395151..5129a6b92b 100644 --- a/src/detect-engine-port.c +++ b/src/detect-engine-port.c @@ -1137,15 +1137,12 @@ static int DetectPortParseMergeNotPorts(const DetectEngineCtx *de_ctx, r = DetectPortCmp(ag, ag2); if (r == PORT_EQ || r == PORT_EB) { /* XXX more ??? */ - if (ag2->prev == NULL) { - *head = ag2->next; - } else { + if (ag2->prev != NULL) ag2->prev->next = ag2->next; - } - - if (ag2->next != NULL) { + if (ag2->next != NULL) ag2->next->prev = ag2->prev; - } + if (*head == ag2) + *head = ag2->next; /** store the next ptr and remove the group */ DetectPort *next_ag2 = ag2->next; DetectPortFree(de_ctx,ag2);