summaryrefslogtreecommitdiffstats
path: root/newlib/libc/locale/lmonetary.c
diff options
context:
space:
mode:
Diffstat (limited to 'newlib/libc/locale/lmonetary.c')
-rw-r--r--newlib/libc/locale/lmonetary.c16
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