From 3351d483881bf64423383e14043cb6a5f2610a84 Mon Sep 17 00:00:00 2001 From: ralfbrown Date: Wed, 2 Oct 2024 13:48:36 -0400 Subject: [PATCH 1/3] check memory allocations for failure in map view --- src/views/map.c | 110 ++++++++++++++++++++++++++---------------------- 1 file changed, 60 insertions(+), 50 deletions(-) diff --git a/src/views/map.c b/src/views/map.c index f7d677f27fce..38be607fb2be 100644 --- a/src/views/map.c +++ b/src/views/map.c @@ -1170,7 +1170,8 @@ static void _view_map_draw_main_location(dt_map_t *lib, if(!d) { d = g_malloc0(sizeof(dt_location_draw_t)); - lib->loc.others = g_list_append(lib->loc.others, d); + if(d) + lib->loc.others = g_list_append(lib->loc.others, d); } if(d) { @@ -1545,52 +1546,58 @@ static void _view_map_changed_callback_delayed(gpointer user_data) if(p[i].cluster_id == NOISE) { dt_map_image_t *entry = (dt_map_image_t *)calloc(1, sizeof(dt_map_image_t)); - entry->imgid = p[i].imgid; - entry->group = p[i].cluster_id; - entry->group_count = 1; - entry->longitude = p[i].x * 180 / M_PI; - entry->latitude = p[i].y * 180 / M_PI; - entry->group_same_loc = TRUE; - if(sel_imgs) - entry->selected_in_group = g_list_find((GList *)sel_imgs, - GINT_TO_POINTER(entry->imgid)) - ? TRUE : FALSE; - lib->images = g_slist_prepend(lib->images, entry); + if(entry) + { + entry->imgid = p[i].imgid; + entry->group = p[i].cluster_id; + entry->group_count = 1; + entry->longitude = p[i].x * 180 / M_PI; + entry->latitude = p[i].y * 180 / M_PI; + entry->group_same_loc = TRUE; + if(sel_imgs) + entry->selected_in_group = g_list_find((GList *)sel_imgs, + GINT_TO_POINTER(entry->imgid)) + ? TRUE : FALSE; + lib->images = g_slist_prepend(lib->images, entry); + } } else if(!processed[p[i].cluster_id]) { processed[p[i].cluster_id] = TRUE; group = p[i].cluster_id; dt_map_image_t *entry = (dt_map_image_t *)calloc(1, sizeof(dt_map_image_t)); - entry->imgid = p[i].imgid; - entry->group = p[i].cluster_id; - entry->group_same_loc = TRUE; - entry->selected_in_group = (sel_imgs && g_list_find((GList *)sel_imgs, - GINT_TO_POINTER(p[i].imgid))) - ? TRUE : FALSE; - const double lon = p[i].x, lat = p[i].y; - - for(int j = 0; j < img_count; j++) + if(entry) { - if(p[j].cluster_id == group) + entry->imgid = p[i].imgid; + entry->group = p[i].cluster_id; + entry->group_same_loc = TRUE; + entry->selected_in_group = (sel_imgs && g_list_find((GList *)sel_imgs, + GINT_TO_POINTER(p[i].imgid))) + ? TRUE : FALSE; + const double lon = p[i].x, lat = p[i].y; + + for(int j = 0; j < img_count; j++) { - entry->group_count++; - entry->longitude += p[j].x; - entry->latitude += p[j].y; - if(entry->group_same_loc && (p[j].x != lon || p[j].y != lat)) + if(p[j].cluster_id == group) { - entry->group_same_loc = FALSE; - } - if(sel_imgs && !entry->selected_in_group) - { - if(g_list_find((GList *)sel_imgs, GINT_TO_POINTER(p[j].imgid))) - entry->selected_in_group = TRUE; + entry->group_count++; + entry->longitude += p[j].x; + entry->latitude += p[j].y; + if(entry->group_same_loc && (p[j].x != lon || p[j].y != lat)) + { + entry->group_same_loc = FALSE; + } + if(sel_imgs && !entry->selected_in_group) + { + if(g_list_find((GList *)sel_imgs, GINT_TO_POINTER(p[j].imgid))) + entry->selected_in_group = TRUE; + } } } + entry->latitude = entry->latitude * 180 / M_PI / entry->group_count; + entry->longitude = entry->longitude * 180 / M_PI / entry->group_count; + lib->images = g_slist_prepend(lib->images, entry); } - entry->latitude = entry->latitude * 180 / M_PI / entry->group_count; - entry->longitude = entry->longitude * 180 / M_PI / entry->group_count; - lib->images = g_slist_prepend(lib->images, entry); } } free(processed); @@ -3092,28 +3099,29 @@ static void _view_map_dnd_get_callback(GtkWidget *widget, if(imgs_nb) { uint32_t *imgs = malloc(sizeof(uint32_t) * imgs_nb); - int i = 0; - for(GList *l = lib->selected_images; - l; - l = g_list_next(l)) + if(imgs) { - imgs[i++] = GPOINTER_TO_INT(l->data); + int i = 0; + for(GList *l = lib->selected_images; + l; + l = g_list_next(l)) + { + imgs[i++] = GPOINTER_TO_INT(l->data); + } + gtk_selection_data_set(selection_data, + gtk_selection_data_get_target(selection_data), + _DWORD, (guchar *)imgs, imgs_nb * sizeof(uint32_t)); + free(imgs); } - gtk_selection_data_set(selection_data, - gtk_selection_data_get_target(selection_data), - _DWORD, (guchar *)imgs, imgs_nb * sizeof(uint32_t)); - free(imgs); } } else if(lib->loc.main.id > 0) { // move of location - uint32_t *imgs = malloc(sizeof(uint32_t)); - imgs[0] = -1; + uint32_t imgs[1] = { -1 }; gtk_selection_data_set(selection_data, gtk_selection_data_get_target(selection_data), _DWORD, (guchar *)imgs, sizeof(uint32_t)); - free(imgs); } } break; @@ -3304,9 +3312,11 @@ static void _bin_points(const dt_map_t *lib, // allocate pointers for all of the latitude bins at this // longitude db.geo_bins[lon_bin] = (geo_bin_t*)calloc(num_lat_bins, sizeof(geo_bin_t)); - - for(int l = 0; l < num_lat_bins; l++) - db.geo_bins[lon_bin][l].points = NO_NEXT_POINT; + if(db.geo_bins[lon_bin]) + { + for(int l = 0; l < num_lat_bins; l++) + db.geo_bins[lon_bin][l].points = NO_NEXT_POINT; + } } // push the point on the front of the linked list for its bin db.points[i].next = db.geo_bins[lon_bin][lat_bin].points; From 1b65969aa91802c038c5c8a14c2c8b0f3dca1038 Mon Sep 17 00:00:00 2001 From: ralfbrown Date: Wed, 2 Oct 2024 13:52:50 -0400 Subject: [PATCH 2/3] check memory allocations for failure in tethering view --- src/views/tethering.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/views/tethering.c b/src/views/tethering.c index fcc39b2dc45e..8fd86a92e527 100644 --- a/src/views/tethering.c +++ b/src/views/tethering.c @@ -211,8 +211,13 @@ static int _tethering_write_image(dt_imageio_module_data_t *data, { _tethering_format_t *d = (_tethering_format_t *)data; d->buf = (float *)malloc(sizeof(float) * 4 * d->head.width * d->head.height); - memcpy(d->buf, in, sizeof(float) * 4 * d->head.width * d->head.height); - return 0; + if(d->buf) + { + memcpy(d->buf, in, sizeof(float) * 4 * d->head.width * d->head.height); + return 0; + } + else + return 1; } #define MARGIN DT_PIXEL_APPLY_DPI(20) @@ -589,11 +594,14 @@ void enter(dt_view_t *self) // register listener lib->listener = g_malloc0(sizeof(dt_camctl_listener_t)); - lib->listener->data = lib; - lib->listener->image_downloaded = _camera_capture_image_downloaded; - lib->listener->request_image_path = _camera_request_image_path; - lib->listener->request_image_filename = _camera_request_image_filename; - dt_camctl_register_listener(darktable.camctl, lib->listener); + if(lib->listener) + { + lib->listener->data = lib; + lib->listener->image_downloaded = _camera_capture_image_downloaded; + lib->listener->request_image_path = _camera_request_image_path; + lib->listener->request_image_filename = _camera_request_image_filename; + dt_camctl_register_listener(darktable.camctl, lib->listener); + } } void leave(dt_view_t *self) From 0d8a738bea2321ef4cd0e8090c9bc08e230b6a1a Mon Sep 17 00:00:00 2001 From: ralfbrown Date: Wed, 2 Oct 2024 13:54:09 -0400 Subject: [PATCH 3/3] check memory allocations for failure in view.c --- src/views/view.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/views/view.c b/src/views/view.c index 518fd11f41d8..eb3725c18d76 100644 --- a/src/views/view.c +++ b/src/views/view.c @@ -1325,10 +1325,15 @@ GSList *dt_mouse_action_create_simple(GSList *actions, const char *const description) { dt_mouse_action_t *a = (dt_mouse_action_t *)calloc(1, sizeof(dt_mouse_action_t)); - a->action = type; - a->mods = accel; - g_strlcpy(a->name, description, sizeof(a->name)); - return g_slist_append(actions, a); + if(a) + { + a->action = type; + a->mods = accel; + g_strlcpy(a->name, description, sizeof(a->name)); + return g_slist_append(actions, a); + } + else + return actions; } GSList *dt_mouse_action_create_format(GSList *actions, @@ -1338,10 +1343,15 @@ GSList *dt_mouse_action_create_format(GSList *actions, const char *const replacement) { dt_mouse_action_t *a = (dt_mouse_action_t *)calloc(1, sizeof(dt_mouse_action_t)); - a->action = type; - a->mods = accel; - g_snprintf(a->name, sizeof(a->name), format_string, replacement); - return g_slist_append(actions, a); + if(a) + { + a->action = type; + a->mods = accel; + g_snprintf(a->name, sizeof(a->name), format_string, replacement); + return g_slist_append(actions, a); + } + else + return actions; } static gchar *_mouse_action_get_string(dt_mouse_action_t *ma)