[Olsr-dev] [PATCH v1 6/8] jsoninfo: avoid a memcpy: just move the abuf.buf pointer and clear abuf

Ferry Huberts (spam-protected)
Fri Nov 27 17:26:15 CET 2015


From: Ferry Huberts <(spam-protected)>

Signed-off-by: Ferry Huberts <(spam-protected)>
---
 lib/jsoninfo/src/olsrd_jsoninfo.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/lib/jsoninfo/src/olsrd_jsoninfo.c b/lib/jsoninfo/src/olsrd_jsoninfo.c
index 2ba7efc..86c7d83 100644
--- a/lib/jsoninfo/src/olsrd_jsoninfo.c
+++ b/lib/jsoninfo/src/olsrd_jsoninfo.c
@@ -1259,12 +1259,15 @@ static void send_info(unsigned int send_what, int the_socket) {
     http_header_adjust_content_length(&abuf, contentLengthPlaceholderStart, abuf.len - headerLength);
   }
 
-  outbuffer[outbuffer_count] = olsr_malloc(abuf.len, PLUGIN_NAME" output buffer");
+  /* avoid a memcpy: just move the abuf.buf pointer and clear abuf */
+  outbuffer[outbuffer_count] = abuf.buf;
   outbuffer_size[outbuffer_count] = abuf.len;
   outbuffer_written[outbuffer_count] = 0;
   outbuffer_socket[outbuffer_count] = the_socket;
+  abuf.buf = NULL;
+  abuf.len = 0;
+  abuf.size = 0;
 
-  memcpy(outbuffer[outbuffer_count], abuf.buf, abuf.len);
   outbuffer_count++;
 
   if (outbuffer_count == 1) {
-- 
2.5.0




More information about the Olsr-dev mailing list