asprintf: Fixed possible memory leak if print fails.
This commit is contained in:
parent
6647f194db
commit
0b1ba70ac5
@ -121,12 +121,16 @@ int vasprintf(FAR char **ptr, FAR const IPTR char *fmt, va_list ap)
|
|||||||
/* Return a pointer to the string to the caller. NOTE: the memstream put()
|
/* Return a pointer to the string to the caller. NOTE: the memstream put()
|
||||||
* method has already added the NUL terminator to the end of the string
|
* method has already added the NUL terminator to the end of the string
|
||||||
* (not included in the nput count).
|
* (not included in the nput count).
|
||||||
*
|
|
||||||
* Hmmm.. looks like the memory would be stranded if lib_vsprintf()
|
|
||||||
* returned an error. Does that ever happen?
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
DEBUGASSERT(nbytes < 0 || nbytes == nulloutstream.nput);
|
DEBUGASSERT(nbytes < 0 || nbytes == nulloutstream.nput);
|
||||||
|
|
||||||
|
if (nbytes < 0)
|
||||||
|
{
|
||||||
|
lib_free(buf);
|
||||||
|
return ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
*ptr = buf;
|
*ptr = buf;
|
||||||
return nbytes;
|
return nbytes;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user