1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-02-22 06:00:41 +00:00

(trunk libT) fix possible memory leak in tr-udp's EV_READ handler.

The EV_READ callback allocates a buffer, but then returns without freeing it if recvfrom() returns <= 0. This commit inverts the logic to avoid returning until the buffer's been free()d.
This commit is contained in:
Jordan Lee 2011-03-04 21:38:04 +00:00
parent 3fdd80eb0d
commit 918f6a96e0

View file

@ -204,9 +204,7 @@ event_callback(int s, short type UNUSED, void *sv)
fromlen = sizeof(from); fromlen = sizeof(from);
rc = recvfrom(s, buf, 4096 - 1, 0, rc = recvfrom(s, buf, 4096 - 1, 0,
(struct sockaddr*)&from, &fromlen); (struct sockaddr*)&from, &fromlen);
if(rc <= 0) if(rc > 0) {
return;
if( buf[0] == 'd' ) { if( buf[0] == 'd' ) {
/* DHT packet. */ /* DHT packet. */
buf[rc] = '\0'; buf[rc] = '\0';
@ -216,6 +214,7 @@ event_callback(int s, short type UNUSED, void *sv)
if(!rc) if(!rc)
tr_ndbg("UDP", "Unexpected UDP packet"); tr_ndbg("UDP", "Unexpected UDP packet");
} }
}
free(buf); free(buf);
} }