Author: mordante
Date: Fri Dec 5 20:51:59 2008
New Revision: 31291
URL: http://svn.gna.org/viewcvs/wesnoth?rev=31291&view=rev
Log:
Fix two realloc issues.
realloc(*ptr, 0) now frees the pointer instead of looking at the current
size of the pointer.
if the malloc fails realloc should return NULL;
Modified:
trunk/src/poolalloc.c
Modified: trunk/src/poolalloc.c
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/poolalloc.c?rev=31291&r1=31290&r2=31291&view=diff
==============================================================================
--- trunk/src/poolalloc.c (original)
+++ trunk/src/poolalloc.c Fri Dec 5 20:51:59 2008
@@ -357,13 +357,17 @@
void* realloc(void* ptr, size_t size)
{
if(IS_OUR_PTR(ptr)) {
- const int old_size =
get_block_from_chunk(ptr)->header.chunk_size;
- if(old_size == 0) {
+ if(size == 0) {
free(ptr);
return NULL;
}
void* new_memory = malloc(size);
+ if(new_memory == NULL) {
+ return NULL;
+ }
+
+ const int old_size =
get_block_from_chunk(ptr)->header.chunk_size;
const size_t nbytes = size < old_size ? size : old_size;
memcpy(new_memory, ptr, nbytes);
free(ptr);
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits