if (!SLIST_EMPTY(&gTraceInfo.bins_info.bins_list) &&
(_find_binary_no_lock(real_path) != NULL)) {
ret = -EALREADY;
- goto add_bin_unlock;
+ goto free_real_path;
}
bin_info = malloc(sizeof(*bin_info));
if (bin_info == NULL) {
ret = -ENOMEM;
- goto add_bin_unlock;
+ goto free_real_path;
}
/* TODO Slow copy / cleanup of memory allocated somewhere else? */
bin_info->path = real_path;
SLIST_INSERT_HEAD(&gTraceInfo.bins_info.bins_list, bin_info, list);
+ /* Success */
+ goto add_bin_unlock;
+
+free_real_path:
+ /* Something went wrong */
+ free(real_path);
add_bin_unlock:
pthread_mutex_unlock(&gTraceInfo.bins_info.bins_mutex);
}
SLIST_REMOVE(&gTraceInfo.bins_info.bins_list, bin_info, bin_info_t, list);
+ free(bin_info->path);
+ free(bin_info);
remove_bin_unlock:
pthread_mutex_unlock(&gTraceInfo.bins_info.bins_mutex);
+ free(real_path);
return ret;
}