WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] fixup memory leak and return value, if malloc or realloc

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] fixup memory leak and return value, if malloc or realloc fail.
From: Xen patchbot -unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Tue, 24 Jan 2006 15:22:07 +0000
Delivery-date: Tue, 24 Jan 2006 15:31:29 +0000
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User vhanquez@xxxxxxxxxxxxxxxxxxxxxxx
# Node ID 45f3b9cfbd83c68be431b7be4ed57376d1db7d51
# Parent  b89b94c71b2fd1e756b33189040d838af388713b
fixup memory leak and return value, if malloc or realloc fail.

Signed-off-by: Vincent Hanquez <vincent@xxxxxxxxxxxxx>

diff -r b89b94c71b2f -r 45f3b9cfbd83 tools/xenstore/utils.c
--- a/tools/xenstore/utils.c    Tue Jan 24 10:52:52 2006
+++ b/tools/xenstore/utils.c    Tue Jan 24 10:55:45 2006
@@ -96,21 +96,29 @@
                return NULL;
 
        buffer = malloc(max+1);
+       if (!buffer)
+               goto error;
        *size = 0;
        while ((ret = read(fd, buffer + *size, max - *size)) > 0) {
                *size += ret;
                if (*size == max) {
+                       void *nbuffer;
                        max *= 2;
-                       buffer = realloc(buffer, max + 1);
+                       nbuffer = realloc(buffer, max + 1);
+                       if (!nbuffer)
+                               goto error;
+                       buffer = nbuffer;
                }
        }
-       if (ret < 0) {
-               free(buffer);
-               buffer = NULL;
-       } else
-               ((char *)buffer)[*size] = '\0';
+       if (ret < 0)
+               goto error;
+       ((char *)buffer)[*size] = '\0';
        close(fd);
        return buffer;
+error:
+       free(buffer);
+       close(fd);
+       return NULL;
 }
 
 void release_file(void *data, unsigned long size __attribute__((unused)))

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] fixup memory leak and return value, if malloc or realloc fail., Xen patchbot -unstable <=