This is the mail archive of the
libc-help@sourceware.org
mailing list for the glibc project.
Using asprintf without memory leaks
- From: Ian Pilcher <arequipeno at gmail dot com>
- To: libc-help at sourceware dot org
- Date: Thu, 26 Nov 2015 16:21:21 -0600
- Subject: Using asprintf without memory leaks
- Authentication-results: sourceware.org; auth=none
asprintf(3) says:
When successful, these functions return the number of bytes printed,
just like sprintf(3). If memory allocation wasn't possible, or some
other error occurs, these functions will return -1, and the contents
of strp is undefined.
If -1 is returned, can I at least assume that any memory that was
allocated has been freed? If not, it's hard to see how asprintf can
be used without risking memory leaks.
--
========================================================================
Ian Pilcher arequipeno@gmail.com
-------- "I grew up before Mark Zuckerberg invented friendship" --------
========================================================================