[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [patch] plug classic realloc() memory leak.
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
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |