diff options
| author | root <[email protected]> | 2024-10-14 02:25:36 +0000 |
|---|---|---|
| committer | root <[email protected]> | 2024-10-14 02:25:36 +0000 |
| commit | 78f733417cf8f11649101dc29aae79326eb553a6 (patch) | |
| tree | a63c74a9a3ce957464a84a2407cb276e134e3d1a /test/test_utils.cpp | |
| parent | 586f1c11b20524066a3b4025cd4a59a14565ad32 (diff) | |
fix memory leak
Diffstat (limited to 'test/test_utils.cpp')
| -rw-r--r-- | test/test_utils.cpp | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/test/test_utils.cpp b/test/test_utils.cpp index 9cfd17a..468adcb 100644 --- a/test/test_utils.cpp +++ b/test/test_utils.cpp @@ -24,6 +24,8 @@ make_serial_rule(const char *table_name, const char *line, void *u_para, enum ma struct serial_rule *s_rule=(struct serial_rule *)u_para; redisContext *ctx = s_rule->ref_ctx; char *buff = ALLOC(char, strlen(line) + 1); + cJSON *rule_uuid = NULL; + int ret = 0; memcpy(buff, line, strlen(line) + 1); @@ -34,16 +36,18 @@ make_serial_rule(const char *table_name, const char *line, void *u_para, enum ma cJSON *json = cJSON_Parse(line); if (NULL == json) { - return -1; + ret = -1; + goto END; } - cJSON *rule_uuid = cJSON_GetObjectItem(json, "uuid"); + rule_uuid = cJSON_GetObjectItem(json, "uuid"); if (NULL == rule_uuid) { rule_uuid = cJSON_GetObjectItem(json, "object_uuid");//for object2object table } if (NULL == rule_uuid || rule_uuid->type != cJSON_String) { - return -1; + ret = -1; + goto END; } maat_set_serial_rule(s_rule + line_idx, op, rule_uuid->valuestring, @@ -51,9 +55,15 @@ make_serial_rule(const char *table_name, const char *line, void *u_para, enum ma (s_rule + line_idx)->ref_ctx = ctx; line_idx++; - FREE(buff); +END: + if (json) { + cJSON_Delete(json); + } + if (buff) { + FREE(buff); + } - return 0; + return ret; } int write_json_to_redis(const char *json_filename, char *redis_ip, int redis_port, @@ -71,6 +81,10 @@ int write_json_to_redis(const char *json_filename, char *redis_ip, int redis_por convert_maat_json_rule(&json_root, (unsigned char *)json_buff); + if (json_buff) { + FREE(json_buff); + } + redisContext *c = maat_connect_redis(redis_ip, redis_port, redis_db, logger); if (NULL == c) { return -1; @@ -162,6 +176,8 @@ int rule_table_set_line(struct maat *maat_inst, const char *table_name, int ret = maat_cmd_set_line(maat_inst, &line_rule, op); free(json_str); + cJSON_Delete(json_root); + return ret; } |
