From 56787fa7b199f3e56307c941bd464b9fcfcde7d5 Mon Sep 17 00:00:00 2001 From: jkh Date: Fri, 13 Jun 2003 00:14:07 +0000 Subject: Fixes to locale code to properly use indirect pointers in order to prevent memory leaks (fixes bugs earlier purported to be fixed). Submitted by: Ed Moy Obtained from: Apple Computer, Inc. MFC after: 2 weeks --- lib/libc/locale/ldpart.c | 12 ++++++------ lib/libc/locale/ldpart.h | 2 +- lib/libc/locale/lmessages.c | 2 +- lib/libc/locale/lmonetary.c | 2 +- lib/libc/locale/lnumeric.c | 2 +- lib/libc/stdtime/timelocal.c | 2 +- 6 files changed, 11 insertions(+), 11 deletions(-) (limited to 'lib') diff --git a/lib/libc/locale/ldpart.c b/lib/libc/locale/ldpart.c index ceb8394..62f92fd 100644 --- a/lib/libc/locale/ldpart.c +++ b/lib/libc/locale/ldpart.c @@ -47,7 +47,7 @@ static int split_lines(char *, const char *); int __part_load_locale(const char *name, int *using_locale, - char *locale_buf, + char **locale_buf, const char *category_filename, int locale_buf_size_max, int locale_buf_size_min, @@ -69,7 +69,7 @@ __part_load_locale(const char *name, /* * If the locale name is the same as our cache, use the cache. */ - if (locale_buf != NULL && strcmp(name, locale_buf) == 0) { + if (*locale_buf != NULL && strcmp(name, *locale_buf) == 0) { *using_locale = 1; return (_LDP_CACHE); } @@ -124,10 +124,10 @@ __part_load_locale(const char *name, /* * Record the successful parse in the cache. */ - if (locale_buf != NULL) - free(locale_buf); - locale_buf = lbuf; - for (p = locale_buf, i = 0; i < num_lines; i++) + if (*locale_buf != NULL) + free(*locale_buf); + *locale_buf = lbuf; + for (p = *locale_buf, i = 0; i < num_lines; i++) dst_localebuf[i] = (p += strlen(p) + 1); for (i = num_lines; i < locale_buf_size_max; i++) dst_localebuf[i] = NULL; diff --git a/lib/libc/locale/ldpart.h b/lib/libc/locale/ldpart.h index becca06..45f7339 100644 --- a/lib/libc/locale/ldpart.h +++ b/lib/libc/locale/ldpart.h @@ -33,7 +33,7 @@ #define _LDP_ERROR (-1) #define _LDP_CACHE 1 -int __part_load_locale(const char *, int*, char *, const char *, +int __part_load_locale(const char *, int*, char **, const char *, int, int, const char **); #endif /* !_LDPART_H_ */ diff --git a/lib/libc/locale/lmessages.c b/lib/libc/locale/lmessages.c index ed58c99..06e56cd 100644 --- a/lib/libc/locale/lmessages.c +++ b/lib/libc/locale/lmessages.c @@ -55,7 +55,7 @@ __messages_load_locale(const char *name) int ret; ret = __part_load_locale(name, &_messages_using_locale, - _messages_locale_buf, "LC_MESSAGES", + &_messages_locale_buf, "LC_MESSAGES", LCMESSAGES_SIZE_FULL, LCMESSAGES_SIZE_MIN, (const char **)&_messages_locale); if (ret == _LDP_LOADED) { diff --git a/lib/libc/locale/lmonetary.c b/lib/libc/locale/lmonetary.c index 1e35bf0..facda8d 100644 --- a/lib/libc/locale/lmonetary.c +++ b/lib/libc/locale/lmonetary.c @@ -88,7 +88,7 @@ __monetary_load_locale(const char *name) int ret; ret = __part_load_locale(name, &_monetary_using_locale, - _monetary_locale_buf, "LC_MONETARY", + &_monetary_locale_buf, "LC_MONETARY", LCMONETARY_SIZE_FULL, LCMONETARY_SIZE_MIN, (const char **)&_monetary_locale); if (ret != _LDP_ERROR) diff --git a/lib/libc/locale/lnumeric.c b/lib/libc/locale/lnumeric.c index 77d2bfa..93acccc 100644 --- a/lib/libc/locale/lnumeric.c +++ b/lib/libc/locale/lnumeric.c @@ -54,7 +54,7 @@ __numeric_load_locale(const char *name) int ret; ret = __part_load_locale(name, &_numeric_using_locale, - _numeric_locale_buf, "LC_NUMERIC", + &_numeric_locale_buf, "LC_NUMERIC", LCNUMERIC_SIZE, LCNUMERIC_SIZE, (const char **)&_numeric_locale); if (ret != _LDP_ERROR) diff --git a/lib/libc/stdtime/timelocal.c b/lib/libc/stdtime/timelocal.c index 88117bd..6917e6b 100644 --- a/lib/libc/stdtime/timelocal.c +++ b/lib/libc/stdtime/timelocal.c @@ -111,7 +111,7 @@ int __time_load_locale(const char *name) { return (__part_load_locale(name, &_time_using_locale, - time_locale_buf, "LC_TIME", + &time_locale_buf, "LC_TIME", LCTIME_SIZE, LCTIME_SIZE, (const char **)&_time_locale)); } -- cgit v1.1