Skip to content
This repository has been archived by the owner on Jul 1, 2022. It is now read-only.

Removed accessing oldptr while realloc has failed. #34

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kstanikviacbs
Copy link

@kstanikviacbs kstanikviacbs commented Jun 27, 2022

Newer versions of compilers fail on:

#12 7.662 In file included from util_memory.c:10:
#12 7.662 util_memory.c: In function ‘nr_realloc’:
#12 7.662 util_logging.h:218:7: error: pointer ‘oldptr’ may be used after ‘realloc’ [-Werror=use-after-free]
#12 7.662   218 |       nrl_send_log_message(NRL_ERROR, __VA_ARGS__); \
#12 7.662       |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#12 7.662 util_memory.c:93:5: note: in expansion of macro ‘nrl_error’
#12 7.662    93 |     nrl_error(NRL_MEMORY, "failed to reallocate %p for %zu bytes", oldptr,
#12 7.662       |     ^~~~~~~~~
#12 7.662 util_memory.c:91:9: note: call to ‘realloc’ here
#12 7.662    91 |   ret = (realloc)(oldptr, newsize);
#12 7.662       |         ^~~~~~~~~~~~~~~~~~~~~~~~~~
#12 7.669 cc1: all warnings being treated as errors
#12 7.671 make[1]: *** [Makefile:165: util_memory.o] Error 1
#12 7.672 make[1]: Leaving directory '/newrelic/vendor/newrelic/axiom'
#12 7.673 make: *** [Makefile:88: vendor/newrelic/axiom/libaxiom.a] Error 2

It's because as stated here: https://en.cppreference.com/w/c/memory/realloc - "The original pointer ptr is invalidated and any access to it is undefined behavior (even if reallocation was in-place).".

@CLAassistant
Copy link

CLAassistant commented Jun 27, 2022

CLA assistant check
All committers have signed the CLA.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants