hanja_list_new()에서 발생할 가능성이 있는 memory leak 수정 80/40280/1
authorChoe Hwanjin <choe.hwanjin@gmail.com>
Mon, 23 Feb 2015 14:57:06 +0000 (23:57 +0900)
committerJihoon Kim <jihoon48.kim@samsung.com>
Tue, 2 Jun 2015 00:29:01 +0000 (09:29 +0900)
strdup이 실패할 경우와 malloc이 실패할 경우에 대한 처리를 강화한다.

Change-Id: I1e8faf0130b2d285fe716f0bea02d6301265d1d8

hangul/hanja.c

index bfad1e0..0cc7349 100644 (file)
@@ -338,18 +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) {
-           if (list->key)
-               free(list->key);
-
-           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;