bio: do not leak memory if realloc fails
This commit is contained in:
parent
e610c573d7
commit
f9b6c4c5a3
1 changed files with 5 additions and 2 deletions
|
@ -6,9 +6,11 @@ static char*
|
||||||
badd(char *p, int *np, char *data, int ndata, int delim, int nulldelim)
|
badd(char *p, int *np, char *data, int ndata, int delim, int nulldelim)
|
||||||
{
|
{
|
||||||
int n;
|
int n;
|
||||||
|
char *oldp;
|
||||||
|
|
||||||
n = *np;
|
n = *np;
|
||||||
p = realloc(p, n+ndata+1);
|
oldp = p;
|
||||||
|
p = realloc(oldp, n+ndata+1);
|
||||||
if(p){
|
if(p){
|
||||||
memmove(p+n, data, ndata);
|
memmove(p+n, data, ndata);
|
||||||
n += ndata;
|
n += ndata;
|
||||||
|
@ -17,7 +19,8 @@ badd(char *p, int *np, char *data, int ndata, int delim, int nulldelim)
|
||||||
else
|
else
|
||||||
p[n] = '\0';
|
p[n] = '\0';
|
||||||
*np = n;
|
*np = n;
|
||||||
}
|
}else
|
||||||
|
free(oldp);
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue