summaryrefslogtreecommitdiff
path: root/mysys/charset.c
diff options
context:
space:
mode:
authorunknown <monty@mysql.com>2003-12-10 00:00:20 +0200
committerunknown <monty@mysql.com>2003-12-10 00:00:20 +0200
commit6b97c26a29127f73c699aaa13ffb5ae9f33703cf (patch)
tree3974a0549628cd8fca7b70530e3d0443783de374 /mysys/charset.c
parent4e85bf326e8051533bb680d1a612813705dc789d (diff)
downloadmariadb-git-6b97c26a29127f73c699aaa13ffb5ae9f33703cf.tar.gz
Added checking of return value from my_once_alloc() in charset
Added checking of return value from malloc() in reg_init() client/mysqltest.c: Added comment dbug/dbug.c: Removed not needed test mysys/charset.c: Added checking of return value from my_once_alloc() regex/reginit.c: Abort if out of memory in reg_init() (unlikely) sql/item_strfunc.cc: Added comment
Diffstat (limited to 'mysys/charset.c')
-rw-r--r--mysys/charset.c54
1 files changed, 39 insertions, 15 deletions
diff --git a/mysys/charset.c b/mysys/charset.c
index ba6733185e0..5e5be9e1b42 100644
--- a/mysys/charset.c
+++ b/mysys/charset.c
@@ -300,7 +300,25 @@ static CHARSET_INFO *find_charset_by_name(CHARSET_INFO **table,
return NULL;
}
-static CHARSET_INFO *add_charset(uint cs_number, const char *cs_name, myf flags)
+/*
+ Read charset from file.
+
+ NOTES
+ One never has to deallocate character sets. They will all be deallocated
+ by my_once_free() when program ends.
+
+ If my_once_alloc() fails then this function may 'leak' some memory
+ which my_once_free() will deallocate, but this is so unlikely to happen
+ that this can be ignored.
+
+ RETURN
+ 0 Error
+ # Pointer to allocated charset structure
+*/
+
+
+static CHARSET_INFO *add_charset(uint cs_number, const char *cs_name,
+ myf flags)
{
CHARSET_INFO tmp_cs,*cs;
uchar tmp_ctype[CTYPE_TABLE_SIZE];
@@ -317,21 +335,27 @@ static CHARSET_INFO *add_charset(uint cs_number, const char *cs_name, myf flags)
cs->sort_order=tmp_sort_order;
cs->strxfrm_multiply=cs->mbmaxlen=1;
if (read_charset_file(cs_number, cs, flags))
- return NULL;
-
- cs = (CHARSET_INFO*) my_once_alloc(sizeof(CHARSET_INFO),
- MYF(MY_WME));
- *cs=tmp_cs;
- cs->name = (char *) my_once_alloc((uint) strlen(cs_name)+1, MYF(MY_WME));
- cs->ctype = (uchar*) my_once_alloc(CTYPE_TABLE_SIZE, MYF(MY_WME));
- cs->to_lower = (uchar*) my_once_alloc(TO_LOWER_TABLE_SIZE, MYF(MY_WME));
- cs->to_upper = (uchar*) my_once_alloc(TO_UPPER_TABLE_SIZE, MYF(MY_WME));
+ return 0;
+
+ if (!(cs= (CHARSET_INFO*) my_once_alloc(sizeof(CHARSET_INFO),
+ MYF(MY_WME))))
+ return 0;
+
+ *cs= tmp_cs;
+ cs->name= (char *) my_once_alloc((uint) strlen(cs_name)+1, MYF(MY_WME));
+ cs->ctype= (uchar*) my_once_alloc(CTYPE_TABLE_SIZE, MYF(MY_WME));
+ cs->to_lower= (uchar*) my_once_alloc(TO_LOWER_TABLE_SIZE, MYF(MY_WME));
+ cs->to_upper= (uchar*) my_once_alloc(TO_UPPER_TABLE_SIZE, MYF(MY_WME));
cs->sort_order=(uchar*) my_once_alloc(SORT_ORDER_TABLE_SIZE, MYF(MY_WME));
- cs->number = cs_number;
- memcpy((char*) cs->name, (char*) cs_name, strlen(cs_name) + 1);
- memcpy((char*) cs->ctype, (char*) tmp_ctype, sizeof(tmp_ctype));
- memcpy((char*) cs->to_lower, (char*) tmp_to_lower, sizeof(tmp_to_lower));
- memcpy((char*) cs->to_upper, (char*) tmp_to_upper, sizeof(tmp_to_upper));
+ if (!cs->name || !cs->ctype || !cs->to_lower || !cs->to_upper ||
+ !cs->sort_order)
+ return 0;
+
+ cs->number= cs_number;
+ memcpy((char*) cs->name, (char*) cs_name, strlen(cs_name) + 1);
+ memcpy((char*) cs->ctype, (char*) tmp_ctype, sizeof(tmp_ctype));
+ memcpy((char*) cs->to_lower, (char*) tmp_to_lower, sizeof(tmp_to_lower));
+ memcpy((char*) cs->to_upper, (char*) tmp_to_upper, sizeof(tmp_to_upper));
memcpy((char*) cs->sort_order, (char*) tmp_sort_order,
sizeof(tmp_sort_order));
insert_dynamic(&cs_info_table, (gptr) &cs);