From 920fe3407f1c85b053a9ea48d8d9f19ef89bf115 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Tue, 12 Apr 2011 09:32:26 -0300 Subject: [PATCH] tools/lib/atnet.c (dialog_vsend): plugged memory leak --- tools/lib/atnet.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tools/lib/atnet.c b/tools/lib/atnet.c index 8b91006..c532663 100644 --- a/tools/lib/atnet.c +++ b/tools/lib/atnet.c @@ -35,7 +35,7 @@ static int dialog_vsend(struct netio *netio, const char *fmt, va_list ap) { va_list ap2; char *buf; - int n; + int n, res; va_copy(ap2, ap); n = vsnprintf(NULL, 0, fmt, ap2); @@ -49,9 +49,10 @@ static int dialog_vsend(struct netio *netio, const char *fmt, va_list ap) vsprintf(buf, fmt, ap); buf[n] = '\n'; - if (netio_write(netio, buf, n+1) < 0) - return -1; - return 0; + res = netio_write(netio, buf, n+1); + free(buf); + + return res < 0 ? -1 : 0; }