aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2024-12-20 12:12:57 +0100
committerThomas White <taw@physics.org>2024-12-20 14:36:06 +0100
commit4142804cb032934b71c5a0a54356b0def5237564 (patch)
tree9e101393752131daac6f146ebf4abc523308076d
parentfb0f0d33dcb98d3453b2bf934406ae04c5d790e9 (diff)
Fix memory allocation routines
-rw-r--r--libcrystfel/src/cell-utils.c8
-rw-r--r--libcrystfel/src/cell-utils.h2
-rw-r--r--libcrystfel/src/datatemplate.c8
-rw-r--r--src/cell_tool.c2
4 files changed, 14 insertions, 6 deletions
diff --git a/libcrystfel/src/cell-utils.c b/libcrystfel/src/cell-utils.c
index 2281082e..54b7cbd0 100644
--- a/libcrystfel/src/cell-utils.c
+++ b/libcrystfel/src/cell-utils.c
@@ -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;
@@ -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);
diff --git a/libcrystfel/src/cell-utils.h b/libcrystfel/src/cell-utils.h
index d4f9a6fd..d15aacda 100644
--- a/libcrystfel/src/cell-utils.h
+++ b/libcrystfel/src/cell-utils.h
@@ -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
diff --git a/libcrystfel/src/datatemplate.c b/libcrystfel/src/datatemplate.c
index a921fe37..bda8b4bf 100644
--- a/libcrystfel/src/datatemplate.c
+++ b/libcrystfel/src/datatemplate.c
@@ -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++;
}
@@ -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 {
@@ -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);
}
}
diff --git a/src/cell_tool.c b/src/cell_tool.c
index 53044994..75bf7314 100644
--- a/src/cell_tool.c
+++ b/src/cell_tool.c
@@ -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;
}