summaryrefslogtreecommitdiff
path: root/sys/src/libbio
diff options
context:
space:
mode:
authorftrvxmtrx <devnull@localhost>2014-05-02 03:58:38 +0200
committerftrvxmtrx <devnull@localhost>2014-05-02 03:58:38 +0200
commitf9b6c4c5a3f10cf4b7166e40b111596c1d6b5102 (patch)
treef6275c9862068c597fd4e95b51779c60f8d01243 /sys/src/libbio
parente610c573d7e2807bacd0a0be1e9cbcef2d3b2eea (diff)
bio: do not leak memory if realloc fails
Diffstat (limited to 'sys/src/libbio')
-rw-r--r--sys/src/libbio/brdstr.c7
1 files changed, 5 insertions, 2 deletions
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;
}