From: ftrvxmtrx Date: Fri, 2 May 2014 01:58:38 +0000 (+0200) Subject: bio: do not leak memory if realloc fails X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=f9b6c4c5a3f10cf4b7166e40b111596c1d6b5102;p=plan9front.git bio: do not leak memory if realloc fails --- diff --git a/sys/src/libbio/brdstr.c b/sys/src/libbio/brdstr.c index a1b14f885..d749795d2 100644 --- a/sys/src/libbio/brdstr.c +++ b/sys/src/libbio/brdstr.c @@ -6,9 +6,11 @@ static char* badd(char *p, int *np, char *data, int ndata, int delim, int nulldelim) { int n; + char *oldp; n = *np; - p = realloc(p, n+ndata+1); + oldp = p; + p = realloc(oldp, n+ndata+1); if(p){ memmove(p+n, data, ndata); n += ndata; @@ -17,7 +19,8 @@ badd(char *p, int *np, char *data, int ndata, int delim, int nulldelim) else p[n] = '\0'; *np = n; - } + }else + free(oldp); return p; }