asprintf: Fixed possible memory leak if print fails.
This commit is contained in:
parent
6647f194db
commit
0b1ba70ac5
1 changed files with 7 additions and 3 deletions
|
@ -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()
|
||||
* method has already added the NUL terminator to the end of the string
|
||||
* (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);
|
||||
|
||||
if (nbytes < 0)
|
||||
{
|
||||
lib_free(buf);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
*ptr = buf;
|
||||
return nbytes;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue