Changeset 12095


Ignore:
Timestamp:
Mar 4, 2011, 9:38:04 PM (11 years ago)
Author:
jordan
Message:

(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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/tr-udp.c

    r12077 r12095  
    205205    rc = recvfrom(s, buf, 4096 - 1, 0,
    206206                  (struct sockaddr*)&from, &fromlen);
    207     if(rc <= 0)
    208         return;
    209 
    210     if( buf[0] == 'd' ) {
    211         /* DHT packet. */
    212         buf[rc] = '\0';
    213         tr_dhtCallback(buf, rc, (struct sockaddr*)&from, fromlen, sv);
    214     } else {
    215         rc = tr_utpPacket(buf, rc, (struct sockaddr*)&from, fromlen, ss);
    216         if(!rc)
    217             tr_ndbg("UDP", "Unexpected UDP packet");
     207    if(rc > 0) {
     208        if( buf[0] == 'd' ) {
     209            /* DHT packet. */
     210            buf[rc] = '\0';
     211            tr_dhtCallback(buf, rc, (struct sockaddr*)&from, fromlen, sv);
     212        } else {
     213            rc = tr_utpPacket(buf, rc, (struct sockaddr*)&from, fromlen, ss);
     214            if(!rc)
     215                tr_ndbg("UDP", "Unexpected UDP packet");
     216        }
    218217    }
    219218
Note: See TracChangeset for help on using the changeset viewer.