]> granicus.if.org Git - transmission/commitdiff
(trunk libT) #4209 "Shortcut UDP tracker test" -- the goal of #4209 is to minimize...
authorJordan Lee <jordan@transmissionbt.com>
Wed, 27 Apr 2011 05:03:10 +0000 (05:03 +0000)
committerJordan Lee <jordan@transmissionbt.com>
Wed, 27 Apr 2011 05:03:10 +0000 (05:03 +0000)
Previously we allocated a 4096 character buffer each time; now we allocate it on the stack. It seems all the distros and OS flavors that Transmission runs on have multi-MB default stack sizes, so a hardwired 4K array should be safe.

libtransmission/tr-udp.c

index dfd3e57b2a2db8c0c07fddd2c334bfe40b6b141a..d310f6a9220a5be2b2c3e1ccf4701e09216355eb 100644 (file)
@@ -188,7 +188,7 @@ static void
 event_callback(int s, short type UNUSED, void *sv)
 {
     tr_session *ss = sv;
-    unsigned char *buf;
+    unsigned char buf[4096];
     struct sockaddr_storage from;
     socklen_t fromlen;
     int rc;
@@ -196,12 +196,6 @@ event_callback(int s, short type UNUSED, void *sv)
     assert(tr_isSession(sv));
     assert(type == EV_READ);
 
-    buf = malloc(4096);
-    if(buf == NULL) {
-        tr_nerr("UDP", "Couldn't allocate buffer");
-        return;
-    }
-
     fromlen = sizeof(from);
     rc = recvfrom(s, buf, 4096 - 1, 0,
                   (struct sockaddr*)&from, &fromlen);
@@ -228,8 +222,6 @@ event_callback(int s, short type UNUSED, void *sv)
                 tr_ndbg("UDP", "Unexpected UDP packet");
         }
     }
-
-    free(buf);
 }
 
 void