summaryrefslogtreecommitdiff
path: root/mysys
diff options
context:
space:
mode:
authorunknown <monty@mashka.mysql.fi>2003-10-16 20:55:15 +0300
committerunknown <monty@mashka.mysql.fi>2003-10-16 20:55:15 +0300
commit4f936a69a798483b318fad4124641256eb0ce380 (patch)
tree15abb95c73d02f77be5ffd9d90398f905401d815 /mysys
parent8ddb4b7c553508fbf48fb3026909a35bac98d32e (diff)
downloadmariadb-git-4f936a69a798483b318fad4124641256eb0ce380.tar.gz
Safety fix to detect multiple calls to my_thread_end()
Portability fix (For Mac OS X) configure.in: Added detection of malloc / sys/malloc include/my_pthread.h: Safety fix to detect multiple calls to my_thread_end() libmysqld/lib_sql.cc: Remove duplicate call to my_thread_end() mysys/charset.c: Cleanup indentation Remove some short variable names mysys/my_thr_init.c: Safety fix to detect multiple calls to my_thread_end() sql/sql_test.cc: Portability fix (For Mac OS X)
Diffstat (limited to 'mysys')
-rw-r--r--mysys/charset.c66
-rw-r--r--mysys/my_thr_init.c9
2 files changed, 50 insertions, 25 deletions
diff --git a/mysys/charset.c b/mysys/charset.c
index 6a64730571c..ba6733185e0 100644
--- a/mysys/charset.c
+++ b/mysys/charset.c
@@ -453,20 +453,37 @@ static my_bool charset_in_string(const char *name, DYNAMIC_STRING *s)
static void charset_append(DYNAMIC_STRING *s, const char *name)
{
- if (!charset_in_string(name, s)) {
+ if (!charset_in_string(name, s))
+ {
dynstr_append(s, name);
dynstr_append(s, " ");
}
}
-/* Returns a dynamically-allocated string listing the character sets
- requested. The caller is responsible for freeing the memory. */
+/*
+ Returns a dynamically-allocated string listing the character sets
+ requested.
+
+ SYNOPSIS
+ list_charsets()
+ want_flags Flags for which character sets to return:
+ MY_COMPILED_SETS: Return incompiled charsets
+ MY_INDEX_SETS:
+ MY_LOADED_SETS:
+
+ NOTES
+ The caller is responsible for freeing the memory.
+
+
+ RETURN
+ A string with available character sets separated by space
+*/
char * list_charsets(myf want_flags)
{
DYNAMIC_STRING s;
- char *p;
+ char *result;
(void)init_available_charsets(MYF(0));
init_dynamic_string(&s, NullS, 256, 1024);
@@ -483,42 +500,45 @@ char * list_charsets(myf want_flags)
if (want_flags & MY_CONFIG_SETS)
{
- CS_ID **c;
+ CS_ID **charset;
char buf[FN_REFLEN];
MY_STAT status;
- if((c=available_charsets))
- for (; *c; ++c)
- {
- if (charset_in_string((*c)->name, &s))
- continue;
- get_charset_conf_name((*c)->number, buf);
- if (!my_stat(buf, &status, MYF(0)))
- continue; /* conf file doesn't exist */
- dynstr_append(&s, (*c)->name);
- dynstr_append(&s, " ");
- }
+ if ((charset=available_charsets))
+ {
+ for (; *charset; charset++)
+ {
+ if (charset_in_string((*charset)->name, &s))
+ continue;
+ get_charset_conf_name((*charset)->number, buf);
+ if (!my_stat(buf, &status, MYF(0)))
+ continue; /* conf file doesn't exist */
+ dynstr_append(&s, (*charset)->name);
+ dynstr_append(&s, " ");
+ }
+ }
}
if (want_flags & MY_INDEX_SETS)
{
- CS_ID **c;
- for (c = available_charsets; *c; ++c)
- charset_append(&s, (*c)->name);
+ CS_ID **charset;
+ for (charset = available_charsets; *charset; charset++)
+ charset_append(&s, (*charset)->name);
}
if (want_flags & MY_LOADED_SETS)
{
uint i;
for (i = 0; i < cs_info_table.elements; i++)
- charset_append(&s,
+ charset_append(&s,
dynamic_element(&cs_info_table, i, CHARSET_INFO *)->name);
}
- s.str[s.length - 1] = '\0'; /* chop trailing space */
- p = my_strdup(s.str, MYF(MY_WME));
+ if (s.length)
+ s.length--; /* Remove end space */
+ result= my_strdup_with_length(s.str, s.length, MYF(MY_WME));
dynstr_free(&s);
- return p;
+ return result;
}
/****************************************************************************
diff --git a/mysys/my_thr_init.c b/mysys/my_thr_init.c
index 59466083b28..9f64e9dcb60 100644
--- a/mysys/my_thr_init.c
+++ b/mysys/my_thr_init.c
@@ -159,6 +159,7 @@ my_bool my_thread_init(void)
tmp->id= ++thread_id;
pthread_mutex_init(&tmp->mutex,MY_MUTEX_INIT_FAST);
pthread_cond_init(&tmp->suspend, NULL);
+ tmp->init= 1;
end:
#if !defined(__WIN__) || defined(USE_TLS) || ! defined(SAFE_MUTEX)
@@ -170,12 +171,14 @@ end:
void my_thread_end(void)
{
- struct st_my_thread_var *tmp=my_thread_var;
+ struct st_my_thread_var *tmp;
+ tmp= my_pthread_getspecific(struct st_my_thread_var*,THR_KEY_mysys);
+
#ifdef EXTRA_DEBUG_THREADS
fprintf(stderr,"my_thread_end(): tmp=%p,thread_id=%ld\n",
tmp,pthread_self());
#endif
- if (tmp)
+ if (tmp && tmp->init)
{
#if !defined(DBUG_OFF)
/* tmp->dbug is allocated inside DBUG library */
@@ -191,6 +194,8 @@ void my_thread_end(void)
pthread_mutex_destroy(&tmp->mutex);
#if (!defined(__WIN__) && !defined(OS2)) || defined(USE_TLS)
free(tmp);
+#else
+ tmp->init= 0;
#endif
}
/* The following free has to be done, even if my_thread_var() is 0 */