From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-3.9 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.1 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 006F4208EC for ; Mon, 16 Jul 2018 21:19:38 +0000 (UTC) From: Eric Wong To: mwrap-public@80x24.org Subject: [PATCH 04/19] realloc: do not copy if allocation failed Date: Mon, 16 Jul 2018 21:19:18 +0000 Message-Id: <20180716211933.5835-5-e@80x24.org> In-Reply-To: <20180716211933.5835-1-e@80x24.org> References: <20180716211933.5835-1-e@80x24.org> List-Id: We shouldn't try to read NULL pointers :x --- ext/mwrap/mwrap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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); -- EW