From: Alan T. DeKok Date: Wed, 2 Aug 2017 13:58:18 +0000 (+0200) Subject: don't malloc / memcpy the packet if we're replicating X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0d45a65c331f1f4fe6defcae4636eb63c9da6ae9;p=thirdparty%2Ffreeradius-server.git don't malloc / memcpy the packet if we're replicating --- diff --git a/src/modules/rlm_radius/rlm_radius_udp.c b/src/modules/rlm_radius/rlm_radius_udp.c index d0adddf12da..14b70e92d20 100644 --- a/src/modules/rlm_radius/rlm_radius_udp.c +++ b/src/modules/rlm_radius/rlm_radius_udp.c @@ -407,6 +407,12 @@ static void conn_writable(fr_event_list_t *el, int fd, UNUSED int flags, void *u request->packet->vps); if (packet_len <= 0) break; + /* + * Might have been sent and then given up + * on... free the raw data. + */ + if (u->packet) TALLOC_FREE(u->packet); + /* * Ad Proxy-State to the tail end of the packet. * We need to add it here, and NOT in @@ -474,17 +480,22 @@ static void conn_writable(fr_event_list_t *el, int fd, UNUSED int flags, void *u // @todo - if debug >= 3, print out hex of the packet. - MEM(u->packet = talloc_memdup(u, c->buffer, packet_len)); - u->packet_len = packet_len; - /* * Write the packet to the socket. If it blocks, * stop dequeueing packets. */ - rcode = write(fd, u->packet, u->packet_len); + rcode = write(fd, c->buffer, packet_len); if (rcode < 0) { - if (errno == EWOULDBLOCK) break; + if (errno == EWOULDBLOCK) { + MEM(u->packet = talloc_memdup(u, c->buffer, packet_len)); + u->packet_len = packet_len; + break; + } + /* + * We have to re-encode the packet, so + * don't bother copying it to 'u'. + */ conn_error(el, fd, 0, errno, c); return; } @@ -499,6 +510,12 @@ static void conn_writable(fr_event_list_t *el, int fd, UNUSED int flags, void *u continue; } + /* + * Only copy the packet if we're not replicating + */ + MEM(u->packet = talloc_memdup(u, c->buffer, packet_len)); + u->packet_len = packet_len; + /* * Start the retransmission timers. */