diff options
Diffstat (limited to 'newlib/libc/locale/lnumeric.c')
-rw-r--r-- | newlib/libc/locale/lnumeric.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/newlib/libc/locale/lnumeric.c b/newlib/libc/locale/lnumeric.c index c488584f3..c63fd8e0f 100644 --- a/newlib/libc/locale/lnumeric.c +++ b/newlib/libc/locale/lnumeric.c @@ -74,13 +74,21 @@ __numeric_load_locale (struct __locale_t *locale, const char *name , { nmp = (struct lc_numeric_T *) calloc (1, sizeof *nmp); if (!nmp) - return -1; - memcpy (nmp, &nm, sizeof *nmp); + { + free (bufp); + return -1; + } + *nmp = nm; } + struct __lc_cats tmp = locale->lc_cat[LC_NUMERIC]; locale->lc_cat[LC_NUMERIC].ptr = ret == 0 ? &_C_numeric_locale : nmp; - if (locale->lc_cat[LC_NUMERIC].buf) - free (locale->lc_cat[LC_NUMERIC].buf); locale->lc_cat[LC_NUMERIC].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 |