strdup이 실패할 경우와 malloc이 실패할 경우에 대한 처리를 강화한다.
Change-Id: I1e8faf0130b2d285fe716f0bea02d6301265d1d8
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;