From: Lee Schermerhorn <lee.schermerhorn@hp.com>
To: Cliff Wickman <cpi@sgi.com>
Cc: Kornilios Kourtis <kkourt@cslab.ece.ntua.gr>,
	Brice Goglin <Brice.Goglin@inria.fr>, <linux-numa@vger.kernel.org>,
	<eric.whitney@hp.com>
Date:	Tue, 28 Apr 2009 12:36:27 -0400
Subject: [PATCH 1/8] numactl/libnuma - Possibly already fixed leaks and cleanup

[PATCH 01/08] Possibly already fixed leaks and cleanup

Against:  numactl-2.0.3-rc2

Kornilios says these [Hunks #1 and 3] are already fixed,
so I pulled them into a separate patch.
  hunk 1
  -919,8 +919,10 @@ void *numa_alloc_onnode(size_t size, int
   	mem = mmap(0, size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS,
   		   0, 0);  
   	if (mem == (char *)-1)
  -		return NULL;		
  -	dombind(mem, size, bind_policy, bmp);
  +		mem = NULL;
  +	else
  +		dombind(mem, size, bind_policy, bmp);
  +	numa_bitmask_free(bmp);
   	return mem; 	
   } 
  hunk 3 (very similar)
    -1496,7 +1499,7 @@ int numa_run_on_node(int node)
    
    int numa_preferred(void)
    { 
   -	int policy;
   +	int policy, node = 0;
 	struct bitmask *bmp;
 
 	bmp = numa_allocate_nodemask();
    -1505,12 +1508,15 @@ int numa_preferred(void)
    		int i;
    		int max = numa_num_possible_nodes();
    		for (i = 0; i < max ; i++) 
   -			if (numa_bitmask_isbitset(bmp, i))
   -				return i; 
   +			if (numa_bitmask_isbitset(bmp, i)) {
   +				node = i;
   +				break;
   +			}
    	}
    	/* could read the current CPU from /proc/self/status. Probably 
    	   not worth it. */
   -	return 0; /* or random one? */
   +	numa_bitmask_free(bmp);
   +	return node;
    }
    
    void numa_set_preferred(int node)

Hunk #2 that modifies numa_alloc_local() just reorganizes the code
to match the structure of numa_alloc_onnode() with, I think, no change
in behavior.  This is probably not "already fixed".

I suppose I could/should change those '(char *)-1's to MAP_FAILED, too...

 libnuma.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Index: numactl-dev/libnuma.c
===================================================================
--- numactl-dev.orig/libnuma.c
+++ numactl-dev/libnuma.c
@@ -940,8 +940,9 @@ void *numa_alloc_local(size_t size)
 	mem = mmap(0, size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS,
 		   0, 0); 
 	if (mem == (char *)-1)
-		return NULL;
-	dombind(mem, size, MPOL_PREFERRED, NULL);
+		mem =  NULL;
+	else
+		dombind(mem, size, MPOL_PREFERRED, NULL);
 	return mem; 	
 } 
 
