[Libvir] Avoid leak upon failed realloc

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

On Fri, Jun 22, 2007 at 11:55:22AM +0200, Jim Meyering wrote:
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@meyering.net>
* qemud/driver.c (qemudMonitorCommand): Avoid leak upon failed realloc.
Yup, always nasty to track, applied, thanks a lot ! Daniel -- Red Hat Virtualization group http://redhat.com/virtualization/ Daniel Veillard | virtualization library http://libvirt.org/ veillard@redhat.com | libxml GNOME XML XSLT toolkit http://xmlsoft.org/ http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/

On Fri, Jun 22, 2007 at 11:55:22AM +0200, Jim Meyering wrote:
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.
Looks good, but please don't apply this to CVS. I'll make the equivalent fix in my QEMU patch series. /me doesn't want to re-diff a series of 20 patches again :-) Dan. -- |=- Red Hat, Engineering, Emerging Technologies, Boston. +1 978 392 2496 -=| |=- Perl modules: http://search.cpan.org/~danberr/ -=| |=- Projects: http://freshmeat.net/~danielpb/ -=| |=- GnuPG: 7D3B9505 F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 -=|

On Fri, Jun 22, 2007 at 12:16:15PM +0100, Daniel P. Berrange wrote:
On Fri, Jun 22, 2007 at 11:55:22AM +0200, Jim Meyering wrote:
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.
Looks good, but please don't apply this to CVS. I'll make the equivalent fix in my QEMU patch series.
/me doesn't want to re-diff a series of 20 patches again :-)
dohh, patch out then :-\ Daniel -- Red Hat Virtualization group http://redhat.com/virtualization/ Daniel Veillard | virtualization library http://libvirt.org/ veillard@redhat.com | libxml GNOME XML XSLT toolkit http://xmlsoft.org/ http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/
participants (3)
-
Daniel P. Berrange
-
Daniel Veillard
-
Jim Meyering