# HG changeset patch # User David Grundberg # Date 1264790082 18000 # Node ID 477d05b0a73948c964fc5568638cc4b24e6c07c8 # Parent f6e0404421f4e3840bf7357ea63215f2a7a01afb mxRealloc: Allocate new memory on NULL argument diff --git a/src/ChangeLog b/src/ChangeLog --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2010-01-29 David Grundberg + + * mex.cc (mex::realloc): Allocate new memory if the argument is + NULL. + 2010-01-29 Ryan Rusaw * pt-eval.h, pt-eval.cc (tree_evaluator::do_keyboard): diff --git a/src/mex.cc b/src/mex.cc --- a/src/mex.cc +++ b/src/mex.cc @@ -2154,27 +2154,35 @@ return ptr; } - // Reallocate a pointer obtained from malloc or calloc. We don't - // need an "unmarked" version of this. + // Reallocate a pointer obtained from malloc or calloc. If the + // pointer is NULL, allocate using malloc. We don't need an + // "unmarked" version of this. void *realloc (void *ptr, size_t n) { - void *v = ::realloc (ptr, n); - - std::set::iterator p = memlist.find (ptr); - - if (v && p != memlist.end ()) + void *v; + + if (ptr) { - memlist.erase (p); - memlist.insert (v); + v = ::realloc (ptr, n); + + std::set::iterator p = memlist.find (ptr); + + if (v && p != memlist.end ()) + { + memlist.erase (p); + memlist.insert (v); + } + + p = global_memlist.find (ptr); + + if (v && p != global_memlist.end ()) + { + global_memlist.erase (p); + global_memlist.insert (v); + } } - - p = global_memlist.find (ptr); - - if (v && p != global_memlist.end ()) - { - global_memlist.erase (p); - global_memlist.insert (v); - } + else + v = malloc (n); return v; }