diff options
author | Corinna Vinschen <corinna@vinschen.de> | 2016-07-23 13:30:21 +0200 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2016-08-15 10:56:57 +0200 |
commit | 1afa0fe4b35f59b7e15c446f47f1d0c2419c89f5 (patch) | |
tree | c7681f0b4d5f3dc717e7c58695adcc9ff472ca8c /newlib/libc/locale/lmessages.c | |
parent | aefd8b5b518b958f64506a6f74aeffb4f47bde8a (diff) | |
download | cygnal-1afa0fe4b35f59b7e15c446f47f1d0c2419c89f5.tar.gz cygnal-1afa0fe4b35f59b7e15c446f47f1d0c2419c89f5.tar.bz2 cygnal-1afa0fe4b35f59b7e15c446f47f1d0c2419c89f5.zip |
Fix memory handling in functions called from loadlocale
Signed-off by: Corinna Vinschen <corinna@vinschen.de>
Diffstat (limited to 'newlib/libc/locale/lmessages.c')
-rw-r--r-- | newlib/libc/locale/lmessages.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/newlib/libc/locale/lmessages.c b/newlib/libc/locale/lmessages.c index cea0c94c8..3780ffbba 100644 --- a/newlib/libc/locale/lmessages.c +++ b/newlib/libc/locale/lmessages.c @@ -84,13 +84,21 @@ __messages_load_locale (struct __locale_t *locale, const char *name, { mep = (struct lc_messages_T *) calloc (1, sizeof *mep); if (!mep) - return -1; - memcpy (mep, &me, sizeof *mep); + { + free (bufp); + return -1; + } + *mep = me; } + struct __lc_cats tmp = locale->lc_cat[LC_MESSAGES]; locale->lc_cat[LC_MESSAGES].ptr = ret == 0 ? &_C_messages_locale : mep; - if (locale->lc_cat[LC_MESSAGES].buf) - free (locale->lc_cat[LC_MESSAGES].buf); locale->lc_cat[LC_MESSAGES].buf = bufp; + /* If buf is not NULL, both pointers have been alloc'ed */ + if (tmp.buf) + { + free ((void *) tmp.ptr); + free (tmp.buf); + } ret = 0; } #else |