summaryrefslogtreecommitdiffstats
path: root/daemon
diff options
context:
space:
mode:
authorJim Meyering <meyering@redhat.com>2009-07-03 12:05:22 +0200
committerJim Meyering <meyering@redhat.com>2009-07-03 17:04:21 +0200
commit0cc0e9e39f816c3f6174c74bf4cb136a5b4e13ea (patch)
tree04092435aaabc865feb81a263be3e4d288919ee5 /daemon
parenta7b73d4a1e09f12b2002083618056f0c823c1dcf (diff)
downloadlibguestfs-0cc0e9e39f816c3f6174c74bf4cb136a5b4e13ea.tar.gz
libguestfs-0cc0e9e39f816c3f6174c74bf4cb136a5b4e13ea.tar.xz
libguestfs-0cc0e9e39f816c3f6174c74bf4cb136a5b4e13ea.zip
avoid leak upon failed realloc
* daemon/guestfsd.c (commandrv): Free original buffer (rather than leaking it) if realloc fails.
Diffstat (limited to 'daemon')
-rw-r--r--daemon/guestfsd.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/daemon/guestfsd.c b/daemon/guestfsd.c
index 581c82e7..87065b9d 100644
--- a/daemon/guestfsd.c
+++ b/daemon/guestfsd.c
@@ -572,19 +572,23 @@ commandrv (char **stdoutput, char **stderror, char * const* const argv)
* trailing \n characters from the error buffer (not from stdout).
*/
if (stdoutput) {
- *stdoutput = realloc (*stdoutput, so_size+1);
- if (*stdoutput == NULL) {
+ void *q = realloc (*stdoutput, so_size+1);
+ if (q == NULL) {
perror ("realloc");
- *stdoutput = NULL;
- } else
+ free (*stdoutput);
+ }
+ *stdoutput = q;
+ if (*stdoutput)
(*stdoutput)[so_size] = '\0';
}
if (stderror) {
- *stderror = realloc (*stderror, se_size+1);
- if (*stderror == NULL) {
+ void *q = realloc (*stderror, se_size+1);
+ if (q == NULL) {
perror ("realloc");
- *stderror = NULL;
- } else {
+ free (*stderror);
+ }
+ *stderror = q;
+ if (*stderror) {
(*stderror)[se_size] = '\0';
se_size--;
while (se_size >= 0 && (*stderror)[se_size] == '\n')