This matters only if/when this realloc call fails. And then, only in
the small way that with this patch, there's a slightly better chance of
recovering from the low-memory condition.
2007-06-22 Jim Meyering <jim(a)meyering.net>
* qemud/driver.c (qemudMonitorCommand): Avoid leak upon failed realloc.
Index: qemud/driver.c
===================================================================
RCS file: /data/cvs/libvirt/qemud/driver.c,v
retrieving revision 1.21
diff -u -p -r1.21 driver.c
--- qemud/driver.c 15 Jun 2007 13:44:19 -0000 1.21
+++ qemud/driver.c 22 Jun 2007 09:43:59 -0000
@@ -75,6 +75,7 @@ int qemudMonitorCommand(struct qemud_ser
for (;;) {
char data[1024];
int got = read(vm->monitor, data, sizeof(data));
+ char *b;
if (got == 0) {
if (buf)
@@ -91,8 +92,11 @@ int qemudMonitorCommand(struct qemud_ser
free(buf);
return -1;
}
- if (!(buf = realloc(buf, size+got+1)))
+ if (!(b = realloc(buf, size+got+1))) {
+ free(buf);
return -1;
+ }
+ buf = b;
memmove(buf+size, data, got);
buf[size+got] = '\0';
size += got;