summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChoe Hwanjin <choe.hwanjin@gmail.com>2015-02-23 23:57:06 +0900
committerChoe Hwanjin <choe.hwanjin@gmail.com>2015-02-23 23:57:06 +0900
commiteeba676cd8781b47c0a52a0e76bc7262ca5e7e75 (patch)
tree70a47e1ba6b2ff1f76b87d8247473e6946bbe676
parent3b8e5572263d3489528e65b204e6bcb75426e043 (diff)
downloadlibhangul-eeba676cd8781b47c0a52a0e76bc7262ca5e7e75.tar.gz
hanja_list_new()에서 발생할 가능성이 있는 memory leak 수정
strdup이 실패할 경우와 malloc이 실패할 경우에 대한 처리를 강화한다.
-rw-r--r--hangul/hanja.c25
1 files changed, 16 insertions, 9 deletions
diff --git a/hangul/hanja.c b/hangul/hanja.c
index 84c57b0..0cc7349 100644
--- a/hangul/hanja.c
+++ b/hangul/hanja.c
@@ -338,15 +338,22 @@ hanja_list_new(const char *key)
HanjaList *list;
list = malloc(sizeof(*list));
- if (list != NULL) {
- list->key = strdup(key);
- list->len = 0;
- list->alloc = 1;
- list->items = malloc(list->alloc * sizeof(list->items[0]));
- if (list->items == NULL) {
- free(list);
- list = NULL;
- }
+ if (list == NULL)
+ return NULL;
+
+ list->key = strdup(key);
+ if (list->key == NULL) {
+ free(list);
+ return NULL;
+ }
+
+ list->len = 0;
+ list->alloc = 1;
+ list->items = malloc(list->alloc * sizeof(list->items[0]));
+ if (list->items == NULL) {
+ free(list->key);
+ free(list);
+ return NULL;
}
return list;