Skip to content

Commit 67ee6e9

Browse files
committed
handle realloc(NULL, ...)
1 parent 54facbb commit 67ee6e9

File tree

1 file changed

+12
-8
lines changed
  • graalpython/com.oracle.graal.python.cext/src

1 file changed

+12
-8
lines changed

graalpython/com.oracle.graal.python.cext/src/obmalloc.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -190,14 +190,18 @@ void* PyMem_RawCalloc(size_t nelem, size_t elsize) {
190190
}
191191

192192
void* PyMem_RawRealloc(void *ptr, size_t new_size) {
193-
mem_head_t* old = ptr != NULL ? AS_MEM_HEAD(ptr) : NULL;
194-
195-
// account for the difference in size
196-
if (old->size >= new_size) {
197-
PyTruffle_FreeMemory(old->size - new_size);
198-
} else {
199-
if (PyTruffle_AllocMemory(new_size - old->size)) {
200-
return NULL;
193+
mem_head_t* old;
194+
195+
if (ptr != NULL) {
196+
ptr = AS_MEM_HEAD(ptr);
197+
198+
// account for the difference in size
199+
if (old->size >= new_size) {
200+
PyTruffle_FreeMemory(old->size - new_size);
201+
} else {
202+
if (PyTruffle_AllocMemory(new_size - old->size)) {
203+
return NULL;
204+
}
201205
}
202206
}
203207

0 commit comments

Comments
 (0)