# HG changeset patch # User Thinker K.F. Li # Date 1222280030 -28800 # Node ID 609ed47a58f285c4e0676f0f7331d23266fd95bc # Parent 7444dea34c6bf2f4ca94e434f462432c19fc12b7 Decrease number of malloc(). diff -r 7444dea34c6b -r 609ed47a58f2 src/shape_path.c --- a/src/shape_path.c Thu Sep 25 01:47:14 2008 +0800 +++ b/src/shape_path.c Thu Sep 25 02:13:50 2008 +0800 @@ -300,8 +300,6 @@ sh_path_t *path = (sh_path_t *)shape; if(path->user_data) free(path->user_data); - if(path->dev_data) - free(path->dev_data); free(path); } @@ -685,24 +683,19 @@ path->cmd_len = cmd_cnt; path->arg_len = arg_cnt; path->fix_arg_len = fix_arg_cnt; + msz = cmd_cnt + sizeof(co_aix) * arg_cnt + sizeof(int) * fix_arg_cnt; - path->user_data = (char *)malloc(msz); + path->user_data = (char *)malloc(msz * 2); if(path->user_data == NULL) { free(path); return NULL; } - path->dev_data = (char *)malloc(msz); - if(path->dev_data == NULL) { - free(path->dev_data); - free(path); - return NULL; - } - memset(path->user_data, 0, cmd_cnt); + path->dev_data = path->user_data + msz; + r = sh_path_cmd_arg_fill(data, path); if(r == ERR) { free(path->user_data); - free(path->dev_data); free(path); return NULL; } @@ -847,8 +840,8 @@ CU_ASSERT(path != NULL); CU_ASSERT(path->cmd_len == ((5 + RESERVED_AIXS + 3) & ~0x3)); CU_ASSERT(path->arg_len == 12); - CU_ASSERT(strcmp(path->user_data, "MLCLZ") == 0); - CU_ASSERT(strcmp(path->dev_data, "MLCLZ") == 0); + CU_ASSERT(strncmp(path->user_data, "MLCLZ", 5) == 0); + CU_ASSERT(strncmp(path->dev_data, "MLCLZ", 5) == 0); args = (co_aix *)(path->user_data + path->cmd_len); CU_ASSERT(args[0] == 33); @@ -876,8 +869,8 @@ CU_ASSERT(path != NULL); CU_ASSERT(path->cmd_len == ((5 + RESERVED_AIXS + 3) & ~0x3)); CU_ASSERT(path->arg_len == 12); - CU_ASSERT(strcmp(path->user_data, "MLCLZ") == 0); - CU_ASSERT(strcmp(path->dev_data, "MLCLZ") == 0); + CU_ASSERT(strncmp(path->user_data, "MLCLZ", 5) == 0); + CU_ASSERT(strncmp(path->dev_data, "MLCLZ", 5) == 0); geo_init(&geo); path->shape.geo = &geo;