asprintf: Fixed possible memory leak if print fails.

This commit is contained in:
Fotis Panagiotopoulos 2023-03-27 12:18:47 +03:00 committed by Alan Carvalho de Assis
parent 6647f194db
commit 0b1ba70ac5

View File

@ -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;
}