From 383c26ea407cf130ad63edfca5bee44e6b282252 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 14 Jul 2018 05:14:11 +0000 Subject: realloc: do not copy if allocation failed We shouldn't try to read NULL pointers :x --- ext/mwrap/mwrap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ext/mwrap/mwrap.c') diff --git a/ext/mwrap/mwrap.c b/ext/mwrap/mwrap.c index 8d8b19f..c0cf8ff 100644 --- a/ext/mwrap/mwrap.c +++ b/ext/mwrap/mwrap.c @@ -545,7 +545,7 @@ void *realloc(void *ptr, size_t size) } rcu_read_unlock(); - if (ptr) { + if (ptr && p) { struct alloc_hdr *old = ptr2hdr(ptr); memcpy(p, ptr, old->size < size ? old->size : size); free(ptr); -- cgit v1.2.3-24-ge0c7