fix invalid free of duplocale object when malloc has been replaced

newlocale and freelocale use __libc_malloc and __libc_free, but
duplocale used malloc. If malloc was replaced, this resulted in
invalid free using the wrong allocator when passing the result of
duplocale to freelocale.

Instead, use libc-internal malloc for duplocale.

This bug was introduced by commit
1e4204d522.
This commit is contained in:
Isaiah Poston 2022-03-12 18:21:56 -06:00 committed by Rich Felker
parent 760f5d7efe
commit 6d8a515796
1 changed files with 5 additions and 0 deletions

View File

@ -3,6 +3,11 @@
#include "locale_impl.h" #include "locale_impl.h"
#include "libc.h" #include "libc.h"
#define malloc __libc_malloc
#define calloc undef
#define realloc undef
#define free undef
locale_t __duplocale(locale_t old) locale_t __duplocale(locale_t old)
{ {
locale_t new = malloc(sizeof *new); locale_t new = malloc(sizeof *new);