Previously, a glib function g_string_free to free GString object was
used like below:
(task_name is a GString object)
1. Assign task_name->str into another char * type variable manually.
2. Free task_name as g_string_free(task_name, FALSE);
This will free GString object without its buffer.
Buffer is provided as a return value but this buffer is already
assigned to another variable, it is ignored.
3. If error occurs, g_string_free(task_name, FALSE) is called.
This may cause memory leak in the error situation and even in the
non-error situation, ignoring the return value of a function call might
cause problem during maintainance.
Thus, it is fixed to get buffer from the return value of
g_string_free_and_steal, which frees GString object and returns buffer.
(It is equivalent to "g_string_free(task_name, FALSE)")
In the error situation, GString object is freed completely with its
buffer.
Change-Id: Idc1f0667819e67fa51823bfc37da523993a1b120
Signed-off-by: SangYoun Kwak <sy.kwak@samsung.com>
}
service_data->task = task;
- service_data->task_name = task_name->str;
+ service_data->task_name = g_string_free_and_steal(task_name);
+ task_name = NULL;
- _D("Task created: %s", task_name->str);
+ _D("Task created: %s", service_data->task_name);
- goto free_resources;
+ return;
error:
if (source != NULL)
if (task != NULL)
tizen_core_task_destroy(task);
- (*failed_count)++;
-
-free_resources:
if (task_name != NULL)
- g_string_free(task_name, FALSE);
+ g_string_free(task_name, TRUE);
+
+ (*failed_count)++;
return;
}