core/protocol: fix leak in send_udp_message

By moving the allocation after some early returns in case of error.

Reported by Coverity as CID #971033.
This commit is contained in:
Riccardo Magliocchetti
2013-03-09 16:52:20 +01:00
parent 851df33977
commit 8cd298de34
+7 -7
View File
@@ -28,13 +28,6 @@ ssize_t send_udp_message(uint8_t modifier1, uint8_t modifier2, char *host, char
struct uwsgi_header *uh;
if (message) {
uh = (struct uwsgi_header *) message;
}
else {
uh = (struct uwsgi_header *) uwsgi_malloc(4);
}
udp_port = strchr(host, ':');
if (udp_port) {
udp_port[0] = 0;
@@ -64,6 +57,13 @@ ssize_t send_udp_message(uint8_t modifier1, uint8_t modifier2, char *host, char
}
if (message) {
uh = (struct uwsgi_header *) message;
}
else {
uh = (struct uwsgi_header *) uwsgi_malloc(4);
}
uh->modifier1 = modifier1;
#ifdef __BIG_ENDIAN__
uh->pktsize = uwsgi_swap16(message_size);