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/lmonetary.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/lmonetary.c')
-rw-r--r-- | newlib/libc/locale/lmonetary.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/newlib/libc/locale/lmonetary.c b/newlib/libc/locale/lmonetary.c index ab770a0fd..b7077a060 100644 --- a/newlib/libc/locale/lmonetary.c +++ b/newlib/libc/locale/lmonetary.c @@ -112,13 +112,21 @@ __monetary_load_locale (struct __locale_t *locale, const char *name , { mop = (struct lc_monetary_T *) calloc (1, sizeof *mop); if (!mop) - return -1; - memcpy (mop, &mo, sizeof *mop); + { + free (bufp); + return -1; + } + *mop = mo; } + struct __lc_cats tmp = locale->lc_cat[LC_MONETARY]; locale->lc_cat[LC_MONETARY].ptr = ret == 0 ? &_C_monetary_locale : mop; - if (locale->lc_cat[LC_MONETARY].buf) - free (locale->lc_cat[LC_MONETARY].buf); locale->lc_cat[LC_MONETARY].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 |