processudp: fix memory leak

send/recvchalresponse should be freed before early returns in the function,
as there are code paths where they would be allocated before these.

Note free is no-op on null pointer so checking for non-null value is useless.

Reported-by: Coverity#375342
This commit is contained in:
Dominique Martinet 2022-11-05 21:18:36 +09:00
parent 4d906e595d
commit af92de5eeb

View file

@ -2705,6 +2705,8 @@ void processudp(uint8_t *buf, int len, struct sockaddr_in *addr, uint16_t indexu
{
LOG(1, s, t, "Invalid length in AVP\n");
STAT(tunnel_rx_errors);
free(sendchalresponse);
free(recvchalresponse);
return;
}
p += n; // next
@ -3250,6 +3252,8 @@ void processudp(uint8_t *buf, int len, struct sockaddr_in *addr, uint16_t indexu
controladd(c, asession, t); // send the message
}
free(sendchalresponse);
free(recvchalresponse);
return;
case 11: // ICRP
LOG(3, s, t, "Received ICRP\n");
@ -3304,8 +3308,8 @@ void processudp(uint8_t *buf, int len, struct sockaddr_in *addr, uint16_t indexu
LOG(1, s, t, "Unknown message type %u\n", message);
break;
}
if (sendchalresponse) free(sendchalresponse);
if (recvchalresponse) free(recvchalresponse);
free(sendchalresponse);
free(recvchalresponse);
cluster_send_tunnel(t);
}
else