Skip to content

Commit 51474ff

Browse files
jeffcTurboGit
authored andcommitted
fix two small memory leaks in the camera import dialog
1 parent 1adfb44 commit 51474ff

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

src/common/camera_control.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff 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
}

src/control/jobs/camera_jobs.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)