Skip to content

Commit

Permalink
Merge pull request #17582 from ralfbrown/view_alloc_checks
Browse files Browse the repository at this point in the history
[maint] check memory allocs in views
  • Loading branch information
TurboGit authored Oct 3, 2024
2 parents 517c0ed + 0d8a738 commit 96df6d6
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 65 deletions.
110 changes: 60 additions & 50 deletions src/views/map.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
22 changes: 15 additions & 7 deletions src/views/tethering.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
26 changes: 18 additions & 8 deletions src/views/view.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand Down

0 comments on commit 96df6d6

Please sign in to comment.