[PATCH] malloc_conf_init: revert errno value when readlink(2) fail.
jasone at canonware.com
Sun Oct 13 16:00:06 PDT 2013
On Sep 20, 2013, at 11:47 AM, Alex <alex at kaworu.ch> wrote:
> In malloc_conf_init(), readlink(2) is called in order to read "/etc/malloc.conf". When readlink(2) fail (which is a common case, for exemple when "/etc/malloc.conf" does not exists) errno is set. This can lead to unexpected behaviour of malloc(), in my case malloc() set errno=2 (ENOENT) because "/etc/malloc.conf" does not exist (see test.c attached).
> I wrote a patch that fixed the issue (against the dev branch). At first I didn't catch the !_WIN32 condition, so review is welcome (I could not test it under Windows). Also I thought it might be better to save & restore errno in malloc_init(), because it could catch other function call modifying errno. Does this make sens ?
Thanks for the patch; I just pushed it on the dev branch. In this case I think it's reasonable to preserve errno, but FWIW jemalloc currently makes no principled effort to preserve errno in non-error cases. The main place this is a real issue right now is in the heap profiling code. It's probably worth cleaning up over time, but I want to make sure that it involves no extra code in the fast path.
More information about the jemalloc-discuss