- if(!g_strcmp0(char_info->char_path, obj_path)) {
- char_info->char_value = g_try_realloc(char_info->char_value, value_length);
- if (char_info->char_value) {
- memcpy(char_info->char_value, value, value_length);
- char_info->value_length = value_length;
- hps_char_list = g_slist_insert_sorted (hps_char_list,
- char_info, char_info_cmp);
+ if (!g_strcmp0(char_info->char_path, obj_path)) {
+ gchar *data = NULL;
+ if (char_info->char_value == NULL) {
+ char_info->char_value = g_malloc0(offset + value_length);
+ char_info->value_length = offset + value_length;
+ } else if (char_info->value_length >= offset + value_length) {
+ /* Just change from offset */
+ memcpy(&char_info->char_value[offset], value, value_length);
+ } else {
+ /* Values crossing pervious allocated limit realloc */
+ data = g_memdup(char_info->char_value, char_info->value_length);
+ char_info->char_value = g_try_realloc(char_info->char_value, offset + value_length);
+ memcpy(char_info->char_value, data, char_info->value_length);
+ memcpy(&char_info->char_value[offset], value, value_length);
+ char_info->value_length = offset + value_length;
+ g_free(data);