diff options
author | Vincent Guittot <vincent.guittot@linaro.org> | 2015-03-24 09:34:42 +0100 |
---|---|---|
committer | Vincent Guittot <vincent.guittot@linaro.org> | 2015-03-24 11:43:08 +0100 |
commit | c4e473bc776a5be40b28ad40fa67eb2cb94528d9 (patch) | |
tree | b905186060f57559ad6653cefa79eefe7a13df46 | |
parent | fc7b4264e75a8c3b26dcbc03fbef8dca7669f7b6 (diff) |
rt-app: fix mem leak
Free string allocated by get_string_value_from once not use anymore
Signed-off-by: Vincent Guittot <vincent.guittot@linaro.org>
-rw-r--r-- | src/rt-app_parse_config.c | 43 |
1 files changed, 38 insertions, 5 deletions
diff --git a/src/rt-app_parse_config.c b/src/rt-app_parse_config.c index 6751511..96e5517 100644 --- a/src/rt-app_parse_config.c +++ b/src/rt-app_parse_config.c @@ -231,6 +231,12 @@ parse_resource_data(const char *name, struct json_object *obj, int idx, exit(EXIT_INV_CONFIG); } + /* + * get_string_value_from allocate the string so with have to free it + * once useless + */ + free(type); + init_resource_data(name, data->type, idx, opts); } @@ -306,7 +312,7 @@ parse_thread_event_data(char *name, struct json_object *obj, { rtapp_resource_t *rdata, *ddata; char unique_name[22]; - const char *ref; + const char *ref, *tmp; int i; if (!strncmp(name, "run", strlen("run")) || @@ -382,11 +388,21 @@ parse_thread_event_data(char *name, struct json_object *obj, ref = get_string_value_from(obj, "ref", TRUE, "unknown"); i = get_resource_index(ref, rtapp_wait, opts); + /* + * get_string_value_from allocate the string so with have to free it + * once useless + */ + free(ref); data->res = i; ref = get_string_value_from(obj, "mutex", TRUE, "unknown"); i = get_resource_index(ref, rtapp_mutex, opts); + /* + * get_string_value_from allocate the string so with have to free it + * once useless + */ + free(ref); data->dep = i; @@ -399,13 +415,20 @@ parse_thread_event_data(char *name, struct json_object *obj, if (!strncmp(name, "timer", strlen("timer"))) { - ref = get_string_value_from(obj, "ref", TRUE, "unknown"); - if (!strncmp(ref, "unique", strlen("unique"))) { - ref = create_unique_name(unique_name, sizeof(unique_name), ref, tag); - } + tmp = get_string_value_from(obj, "ref", TRUE, "unknown"); + if (!strncmp(tmp, "unique", strlen("unique"))) + ref = create_unique_name(unique_name, sizeof(unique_name), tmp, tag); + else + ref = tmp; i = get_resource_index(ref, rtapp_timer, opts); + /* + * get_string_value_from allocate the string so with have to free it + * once useless + */ + free(tmp); + data->res = i; data->duration = get_int_value_from(obj, "period", TRUE, 0); @@ -698,6 +721,11 @@ parse_global(struct json_object *global, rtapp_options_t *opts) log_critical(PFX "Invalid policy %s", policy); exit(EXIT_INV_CONFIG); } + /* + * get_string_value_from allocate the string so with have to free it + * once useless + */ + free(policy); cal_obj = get_in_object(global, "calibration", TRUE); if (cal_obj == NULL) { @@ -715,6 +743,11 @@ parse_global(struct json_object *global, rtapp_options_t *opts) cal_str = get_string_value_from(global, "calibration", TRUE, "CPU0"); scan_cnt = sscanf(cal_str, "CPU%d", &opts->calib_cpu); + /* + * get_string_value_from allocate the string so with have to free it + * once useless + */ + free(cal_str); if (!scan_cnt) { log_critical(PFX "Invalid calibration CPU%d", opts->calib_cpu); exit(EXIT_INV_CONFIG); |