From eeba676cd8781b47c0a52a0e76bc7262ca5e7e75 Mon Sep 17 00:00:00 2001 From: Choe Hwanjin Date: Mon, 23 Feb 2015 23:57:06 +0900 Subject: =?UTF-8?q?hanja=5Flist=5Fnew()=EC=97=90=EC=84=9C=20=EB=B0=9C?= =?UTF-8?q?=EC=83=9D=ED=95=A0=20=EA=B0=80=EB=8A=A5=EC=84=B1=EC=9D=B4=20?= =?UTF-8?q?=EC=9E=88=EB=8A=94=20memory=20leak=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit strdup이 실패할 경우와 malloc이 실패할 경우에 대한 처리를 강화한다. --- hangul/hanja.c | 25 ++++++++++++++++--------- 1 file 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; -- cgit v1.2.1