Skip to content

Commit

Permalink
Fix memory allocation routines
Browse files Browse the repository at this point in the history
  • Loading branch information
taw10 committed Dec 20, 2024
1 parent fb0f0d3 commit 4142804
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
8 changes: 7 additions & 1 deletion libcrystfel/src/cell-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -2505,6 +2505,12 @@ SymOpList *get_lattice_symmetry(UnitCell *cell)
}


void free_powder_rings(struct powder_ring *r)
{
cffree(r);
}


static int cmpres(const void *av, const void *bv)
{
const struct powder_ring *a = av;
Expand Down Expand Up @@ -2565,7 +2571,7 @@ struct powder_ring *powder_rings(UnitCell *cell, SymOpList *sym, double mres,
}

n = num_reflections(list);
sortus = malloc(n*sizeof(struct powder_ring));
sortus = cfmalloc(n*sizeof(struct powder_ring));

i = 0;
for ( ring = first_refl(list, &iter);
Expand Down
2 changes: 2 additions & 0 deletions libcrystfel/src/cell-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ extern struct powder_ring *powder_rings(UnitCell *cell,
double mres,
int *n_rings);

extern void free_powder_rings(struct powder_ring *r);

#ifdef __cplusplus
}
#endif
Expand Down
8 changes: 4 additions & 4 deletions libcrystfel/src/datatemplate.c
Original file line number Diff line number Diff line change
Expand Up @@ -847,8 +847,8 @@ static void store_for_later(struct forlater *fl, const char *key, const char *va
return;
}

fl->keys[fl->n_forlater] = strdup(key);
fl->vals[fl->n_forlater] = strdup(val);
fl->keys[fl->n_forlater] = cfstrdup(key);
fl->vals[fl->n_forlater] = cfstrdup(val);
fl->n_forlater++;
}

Expand Down Expand Up @@ -1462,7 +1462,7 @@ DataTemplate *data_template_new_from_string(const char *string_in)
/* If no groups are defined, put everything in one group.
* This allows at least basic geometry refinement to work. */
if ( dt->n_groups == dt->n_panels ) {
char **allg = malloc(dt->n_groups*sizeof(char *));
char **allg = cfmalloc(dt->n_groups*sizeof(char *));
if ( allg == NULL ) {
ERROR("Failed to create top group\n");
} else {
Expand All @@ -1471,7 +1471,7 @@ DataTemplate *data_template_new_from_string(const char *string_in)
allg[i] = dt->groups[i]->name;
}
add_group_members("all", dt, allg, dt->n_groups);
free(allg);
cffree(allg);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/cell_tool.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ static int all_rings(UnitCell *cell, SymOpList *sym, double mres)
rings[i].multi);
}

free(rings);
free_powder_rings(rings);

return 0;
}
Expand Down

0 comments on commit 4142804

Please sign in to comment.