 151f85a471
			
		
	
	
	151f85a471
	
	
	
		
			
			All the functions that call this can handle the equivalent, non panic'ing wrapped routines. Cc: Frédéric Weisbecker <fweisbec@gmail.com> Cc: Mike Galbraith <efault@gmx.de> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Tom Zanussi <tzanussi@gmail.com> LKML-Reference: <new-submission> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
		
			
				
	
	
		
			40 lines
		
	
	
	
		
			790 B
			
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			40 lines
		
	
	
	
		
			790 B
			
		
	
	
	
		
			C
		
	
	
	
	
	
| /*
 | |
|  * Various trivial helper wrappers around standard functions
 | |
|  */
 | |
| #include "cache.h"
 | |
| 
 | |
| /*
 | |
|  * There's no pack memory to release - but stay close to the Git
 | |
|  * version so wrap this away:
 | |
|  */
 | |
| static inline void release_pack_memory(size_t size __used, int flag __used)
 | |
| {
 | |
| }
 | |
| 
 | |
| char *xstrdup(const char *str)
 | |
| {
 | |
| 	char *ret = strdup(str);
 | |
| 	if (!ret) {
 | |
| 		release_pack_memory(strlen(str) + 1, -1);
 | |
| 		ret = strdup(str);
 | |
| 		if (!ret)
 | |
| 			die("Out of memory, strdup failed");
 | |
| 	}
 | |
| 	return ret;
 | |
| }
 | |
| 
 | |
| void *xrealloc(void *ptr, size_t size)
 | |
| {
 | |
| 	void *ret = realloc(ptr, size);
 | |
| 	if (!ret && !size)
 | |
| 		ret = realloc(ptr, 1);
 | |
| 	if (!ret) {
 | |
| 		release_pack_memory(size, -1);
 | |
| 		ret = realloc(ptr, size);
 | |
| 		if (!ret && !size)
 | |
| 			ret = realloc(ptr, 1);
 | |
| 		if (!ret)
 | |
| 			die("Out of memory, realloc failed");
 | |
| 	}
 | |
| 	return ret;
 | |
| }
 |