File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1256,7 +1256,11 @@ void dt_camctl_import(const dt_camctl_t *c,
12561256 const dt_camera_t * cam ,
12571257 GList * images )
12581258{
1259- GList * ifiles = g_list_sort (images , (GCompareFunc )_sort_filename );
1259+ // Copy the list structure first. g_list_sort sorts in-place and modifies the list nodes,
1260+ // which would change the head pointer seen by the caller (params->images).
1261+ // Copying preserves the original list structure so the caller can successfully free it.
1262+ GList * ifiles = g_list_copy (images );
1263+ ifiles = g_list_sort (ifiles , (GCompareFunc )_sort_filename );
12601264 char * prev_file = NULL ;
12611265 char * prev_output = NULL ;
12621266
@@ -1341,6 +1345,11 @@ void dt_camctl_import(const dt_camctl_t *c,
13411345 }
13421346 g_free (prev_output );
13431347
1348+ // Free only the copied list nodes. The actual filename strings are still owned
1349+ // by the original list 'images' and will be freed by the caller's cleanup handler.
1350+ // Using g_list_free_full here would result in a use-after-free or double-free.
1351+ g_list_free (ifiles );
1352+
13441353 _dispatch_control_status (c , CAMERA_CONTROL_AVAILABLE );
13451354 _camctl_unlock (c );
13461355}
Original file line number Diff line number Diff line change @@ -369,7 +369,9 @@ static void dt_camera_import_cleanup(void *p)
369369{
370370 dt_camera_import_t * params = p ;
371371
372- g_list_free (params -> images );
372+ // Free the dynamically allocated filename strings in the list, then the list itself.
373+ // These strings were allocated by gtk_tree_model_get in import.c:_import_from_dialog_run.
374+ g_list_free_full (params -> images , g_free );
373375
374376 dt_import_session_destroy (params -> shared .session );
375377
You can’t perform that action at this time.
0 commit comments