ia64/xen-unstable

changeset 10404:578e306b0bd4

[XENSTAT] Fix two realloc() usage errors in xenstat.
Based on original patch from Jimi Xenidis at IBM.
Signed-off-by: Keir Fraser <keir@xensource.com>
author kfraser@dhcp93.uk.xensource.com
date Wed Jun 14 13:31:38 2006 +0100 (2006-06-14)
parents 1e49997c8146
children 63967ff8d459
files tools/xenstat/libxenstat/src/xenstat.c
line diff
     1.1 --- a/tools/xenstat/libxenstat/src/xenstat.c	Wed Jun 14 13:11:44 2006 +0100
     1.2 +++ b/tools/xenstat/libxenstat/src/xenstat.c	Wed Jun 14 13:31:38 2006 +0100
     1.3 @@ -223,18 +223,20 @@ xenstat_node *xenstat_get_node(xenstat_h
     1.4  
     1.5  	num_domains = 0;
     1.6  	do {
     1.7 -		xenstat_domain *domain;
     1.8 +		xenstat_domain *domain, *tmp;
     1.9  
    1.10  		new_domains = xc_domain_getinfolist(handle->xc_handle,
    1.11  			num_domains, DOMAIN_CHUNK_SIZE, domaininfo);
    1.12  
    1.13 -		node->domains = realloc(node->domains,
    1.14 -					(num_domains + new_domains)
    1.15 -					* sizeof(xenstat_domain));
    1.16 -		if (node->domains == NULL) {
    1.17 +		tmp = realloc(node->domains,
    1.18 +			      (num_domains + new_domains)
    1.19 +			      * sizeof(xenstat_domain));
    1.20 +		if (tmp == NULL) {
    1.21 +			free(node->domains);
    1.22  			free(node);
    1.23  			return NULL;
    1.24  		}
    1.25 +		node->domains = tmp;
    1.26  
    1.27  		domain = node->domains + num_domains;
    1.28  
    1.29 @@ -582,11 +584,14 @@ static int xenstat_collect_networks(xens
    1.30  			domain->num_networks = 1;
    1.31  			domain->networks = malloc(sizeof(xenstat_network));
    1.32  		} else {
    1.33 +			struct xenstat_network *tmp;
    1.34  			domain->num_networks++;
    1.35 -			domain->networks =
    1.36 -			    realloc(domain->networks,
    1.37 -				    domain->num_networks *
    1.38 -				    sizeof(xenstat_network));
    1.39 +			tmp = realloc(domain->networks,
    1.40 +				      domain->num_networks *
    1.41 +				      sizeof(xenstat_network));
    1.42 +			if (tmp == NULL)
    1.43 +				free(domain->networks);
    1.44 +			domain->networks = tmp;
    1.45  		}
    1.46  		if (domain->networks == NULL)
    1.47  			return 0;