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-devel

[Xen-devel] [patch] plug classic realloc() memory leak.

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [patch] plug classic realloc() memory leak.
From: Jimi Xenidis <jimix@xxxxxxxxxxxxxx>
Date: Tue, 13 Jun 2006 17:42:28 -0400
Delivery-date: Tue, 13 Jun 2006 14:42:18 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
This patch fixes the classic bug/memory leak where realloc(3) on
failure returns a NULL but the original original allocation is still
valid and needs to be freed.

NOTE: diff is wierd bcause the file contains hard-tabs and thats a no-no.

Signed-off-by: Jimi Xenidis <jimix@xxxxxxxxxxxxxx>
--
diff -r 7b25f1309eb1 tools/xenstat/libxenstat/src/xenstat.c
--- a/tools/xenstat/libxenstat/src/xenstat.c    Tue Jun 13 15:14:57 2006 -0400
+++ b/tools/xenstat/libxenstat/src/xenstat.c    Tue Jun 13 17:18:36 2006 -0400
@@ -224,18 +224,20 @@ xenstat_node *xenstat_get_node(xenstat_h
        num_domains = 0;
        do {
                xenstat_domain *domain;
+        xenstat_domain *tmp;
 
                new_domains = xc_domain_getinfolist(handle->xc_handle,
                        num_domains, DOMAIN_CHUNK_SIZE, domaininfo);
 
-               node->domains = realloc(node->domains,
+        tmp = realloc(node->domains,
                                        (num_domains + new_domains)
                                        * sizeof(xenstat_domain));
-               if (node->domains == NULL) {
+        if (tmp == NULL) {
+            free(node->domains);
                        free(node);
                        return NULL;
                }
-
+        node->domains = tmp;
                domain = node->domains + num_domains;
 
                for (i = 0; i < new_domains; i++) {

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

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-devel] [patch] plug classic realloc() memory leak., Jimi Xenidis <=