Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/common/camera_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -1256,7 +1256,11 @@ void dt_camctl_import(const dt_camctl_t *c,
const dt_camera_t *cam,
GList *images)
{
GList *ifiles = g_list_sort(images, (GCompareFunc)_sort_filename);
// Copy the list structure first. g_list_sort sorts in-place and modifies the list nodes,
// which would change the head pointer seen by the caller (params->images).
// Copying preserves the original list structure so the caller can successfully free it.
GList *ifiles = g_list_copy(images);
ifiles = g_list_sort(ifiles, (GCompareFunc)_sort_filename);
char *prev_file = NULL;
char *prev_output = NULL;

Expand Down Expand Up @@ -1341,6 +1345,11 @@ void dt_camctl_import(const dt_camctl_t *c,
}
g_free(prev_output);

// Free only the copied list nodes. The actual filename strings are still owned
// by the original list 'images' and will be freed by the caller's cleanup handler.
// Using g_list_free_full here would result in a use-after-free or double-free.
g_list_free(ifiles);

_dispatch_control_status(c, CAMERA_CONTROL_AVAILABLE);
_camctl_unlock(c);
}
Expand Down
4 changes: 3 additions & 1 deletion src/control/jobs/camera_jobs.c
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,9 @@ static void dt_camera_import_cleanup(void *p)
{
dt_camera_import_t *params = p;

g_list_free(params->images);
// Free the dynamically allocated filename strings in the list, then the list itself.
// These strings were allocated by gtk_tree_model_get in import.c:_import_from_dialog_run.
g_list_free_full(params->images, g_free);

dt_import_session_destroy(params->shared.session);

Expand Down
Loading