From ea3fe42ca3bfa6ec264bc2732f5cb72c63b37ae5 Mon Sep 17 00:00:00 2001 From: Jordan Lee Date: Wed, 27 Apr 2011 05:03:10 +0000 Subject: [PATCH] (trunk libT) #4209 "Shortcut UDP tracker test" -- the goal of #4209 is to minimize the cost of the UDP event callback function, so apply the heap pruning eye to that by removing an unnecessary malloc/free call there. 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 | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/libtransmission/tr-udp.c b/libtransmission/tr-udp.c index dfd3e57b2..d310f6a92 100644 --- a/libtransmission/tr-udp.c +++ b/libtransmission/tr-udp.c @@ -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 -- 2.40.0