From 0c2ea689cf141394eecb6ce30401ec7eaad740e9 Mon Sep 17 00:00:00 2001 From: Dengfeng Liu Date: Tue, 18 Apr 2017 14:40:42 +0800 Subject: [PATCH] Update xkcp_spy.c --- xkcp_spy.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/xkcp_spy.c b/xkcp_spy.c index dfa9e74..079a1ae 100644 --- a/xkcp_spy.c +++ b/xkcp_spy.c @@ -54,14 +54,14 @@ static void readcb(struct bufferevent *bev, void *ctx) { struct event_base *base = ctx; struct evbuffer *input = bufferevent_get_input(bev); - char buf[1024] = {0}; - int len; - - while ((len = evbuffer_remove(input, buf, sizeof(buf)-1)) > 0) { - printf("%s", buf); - memset(buf, 0, 1024); - } - printf("\n"); + int len = evbuffer_get_length(input); + + if (len > 0) { + char *buf = malloc(len+1); + memset(buf, 0, len+1); + evbuffer_remove(input, buf, len); + printf("%s\n", buf); + } event_base_loopexit(base, NULL); }