diff options
Diffstat (limited to 'libcrystfel/src')
37 files changed, 1039 insertions, 1040 deletions
diff --git a/libcrystfel/src/cell-utils.c b/libcrystfel/src/cell-utils.c index 2398c5f2..d751172e 100644 --- a/libcrystfel/src/cell-utils.c +++ b/libcrystfel/src/cell-utils.c @@ -996,14 +996,14 @@ UnitCell *load_cell_from_file(const char *filename) n1 = assplode(line, " \t", &bits, ASSPLODE_NONE); if ( n1 < 3 ) { - for ( i=0; i<n1; i++ ) free(bits[i]); - free(bits); + for ( i=0; i<n1; i++ ) cffree(bits[i]); + cffree(bits); continue; } if ( bits[0][0] == ';' ) { - for ( i=0; i<n1; i++ ) free(bits[i]); - free(bits); + for ( i=0; i<n1; i++ ) cffree(bits[i]); + cffree(bits); continue; } @@ -1061,8 +1061,8 @@ UnitCell *load_cell_from_file(const char *filename) ERROR("Unrecognised field '%s'\n", bits[0]); } - for ( i=0; i<n1; i++ ) free(bits[i]); - free(bits); + for ( i=0; i<n1; i++ ) cffree(bits[i]); + cffree(bits); } while ( rval != NULL ); @@ -1588,12 +1588,12 @@ static Rational *find_candidates(double len, double *a, double *b, double *c, int ia, ib, ic; int i; - cands = malloc(max_cand * sizeof(struct cand)); + cands = cfmalloc(max_cand * sizeof(struct cand)); if ( cands == NULL ) return NULL; rat = rtnl_list(-5, 5, 1, csl ? 4 : 1, &nrat); if ( rat == NULL ) { - free(cands); + cffree(cands); return NULL; } @@ -1632,7 +1632,7 @@ static Rational *find_candidates(double len, double *a, double *b, double *c, /* Sort by difference from reference vector length */ qsort(cands, ncand, sizeof(struct cand), cmpcand); - r = malloc(ncand * 3 * sizeof(Rational)); + r = cfmalloc(ncand * 3 * sizeof(Rational)); if ( r == 0 ) return NULL; for ( i=0; i<ncand; i++ ) { @@ -1640,7 +1640,7 @@ static Rational *find_candidates(double len, double *a, double *b, double *c, r[3*i+1] = cands[i].abc[1]; r[3*i+2] = cands[i].abc[2]; } - free(cands); + cffree(cands); *pncand = ncand; return r; @@ -1823,9 +1823,9 @@ int compare_derivative_cell_parameters(UnitCell *cell_in, UnitCell *reference_in } rtnl_mtx_free(M); - free(cand_a); - free(cand_b); - free(cand_c); + cffree(cand_a); + cffree(cand_b); + cffree(cand_c); if ( CiAMCB == NULL ) { *pmb = NULL; diff --git a/libcrystfel/src/cell.c b/libcrystfel/src/cell.c index 775567e3..60f6ef58 100644 --- a/libcrystfel/src/cell.c +++ b/libcrystfel/src/cell.c @@ -109,7 +109,7 @@ UnitCell *cell_new() { UnitCell *cell; - cell = malloc(sizeof(UnitCell)); + cell = cfmalloc(sizeof(UnitCell)); if ( cell == NULL ) return NULL; cell->a = 1.0; @@ -140,7 +140,7 @@ UnitCell *cell_new() void cell_free(UnitCell *cell) { if ( cell == NULL ) return; - free(cell); + cffree(cell); } diff --git a/libcrystfel/src/crystal.c b/libcrystfel/src/crystal.c index cece3eb4..e5978795 100644 --- a/libcrystfel/src/crystal.c +++ b/libcrystfel/src/crystal.c @@ -81,7 +81,7 @@ Crystal *crystal_new() { Crystal *cryst; - cryst = malloc(sizeof(Crystal)); + cryst = cfmalloc(sizeof(Crystal)); if ( cryst == NULL ) return NULL; cryst->cell = NULL; @@ -116,7 +116,7 @@ Crystal *crystal_copy(const Crystal *cryst) if ( c == NULL ) return NULL; memcpy(c, cryst, sizeof(Crystal)); - if ( c->notes != NULL ) c->notes = strdup(c->notes); + if ( c->notes != NULL ) c->notes = cfstrdup(c->notes); return c; } @@ -140,7 +140,7 @@ Crystal *crystal_copy_deep(const Crystal *cryst) if ( c == NULL ) return NULL; memcpy(c, cryst, sizeof(Crystal)); - if ( c->notes != NULL ) c->notes = strdup(c->notes); + if ( c->notes != NULL ) c->notes = cfstrdup(c->notes); if ( cryst->cell != NULL ) { UnitCell *cell; @@ -169,8 +169,8 @@ Crystal *crystal_copy_deep(const Crystal *cryst) void crystal_free(Crystal *cryst) { if ( cryst == NULL ) return; - free(cryst->notes); - free(cryst); + cffree(cryst->notes); + cffree(cryst); } @@ -322,8 +322,8 @@ void crystal_set_mosaicity(Crystal *cryst, double m) void crystal_set_notes(Crystal *cryst, const char *notes) { - free(cryst->notes); /* free(NULL) is OK */ - cryst->notes = strdup(notes); + cffree(cryst->notes); /* free(NULL) is OK */ + cryst->notes = cfstrdup(notes); } @@ -338,7 +338,7 @@ void crystal_add_notes(Crystal *cryst, const char *notes_add) } len = strlen(notes_add) + strlen(cryst->notes) + 2; - nnotes = malloc(len); + nnotes = cfmalloc(len); if ( nnotes == NULL ) { ERROR("Failed to add notes to crystal.\n"); return; @@ -347,7 +347,7 @@ void crystal_add_notes(Crystal *cryst, const char *notes_add) strcpy(nnotes, cryst->notes); strcat(nnotes, "\n"); strcat(nnotes, notes_add); - free(cryst->notes); + cffree(cryst->notes); cryst->notes = nnotes; } diff --git a/libcrystfel/src/crystfel-mille.c b/libcrystfel/src/crystfel-mille.c index 8eacaa60..381ee60a 100644 --- a/libcrystfel/src/crystfel-mille.c +++ b/libcrystfel/src/crystfel-mille.c @@ -106,8 +106,8 @@ static void mille_add_measurement(Mille *m, new_max_entries *= 2; } - new_float_arr = realloc(m->float_arr, new_max_entries*sizeof(float)); - new_int_arr = realloc(m->int_arr, new_max_entries*sizeof(int)); + new_float_arr = cfrealloc(m->float_arr, new_max_entries*sizeof(float)); + new_int_arr = cfrealloc(m->int_arr, new_max_entries*sizeof(int)); if ( (new_float_arr == NULL) || (new_int_arr == NULL) ) return; m->float_arr = new_float_arr; @@ -285,7 +285,7 @@ Mille *crystfel_mille_new(const char *outFileName) { Mille *m; - m = malloc(sizeof(Mille)); + m = cfmalloc(sizeof(Mille)); if ( m == NULL ) return NULL; m->max_entries = 0; @@ -296,7 +296,7 @@ Mille *crystfel_mille_new(const char *outFileName) m->fh = fopen(outFileName, "wb"); if ( m->fh == NULL ) { ERROR("Failed to open Mille file '%s'\n", outFileName); - free(m); + cffree(m); return NULL; } @@ -309,9 +309,9 @@ void crystfel_mille_free(Mille *m) { if ( m == NULL ) return; fclose(m->fh); - free(m->float_arr); - free(m->int_arr); - free(m); + cffree(m->float_arr); + cffree(m->int_arr); + cffree(m); } diff --git a/libcrystfel/src/datatemplate.c b/libcrystfel/src/datatemplate.c index a01baba5..9c992c70 100644 --- a/libcrystfel/src/datatemplate.c +++ b/libcrystfel/src/datatemplate.c @@ -73,14 +73,14 @@ static struct panel_group_template *add_group(const char *name, DataTemplate *dt return NULL; } - gt = malloc(sizeof(struct panel_group_template)); + gt = cfmalloc(sizeof(struct panel_group_template)); if ( gt == NULL ) return NULL; - gt->name = strdup(name); + gt->name = cfstrdup(name); gt->n_children = 0; if ( gt->name == NULL ) { - free(gt); + cffree(gt); return NULL; } @@ -140,8 +140,8 @@ static int parse_group(const char *name, DataTemplate *dt, const char *val) } - for ( i=0; i<n_members; i++ ) free(members[i]); - free(members); + for ( i=0; i<n_members; i++ ) cffree(members[i]); + cffree(members); return fail; } @@ -156,14 +156,14 @@ static struct panel_template *new_panel(DataTemplate *det, int i; det->n_panels++; - det->panels = realloc(det->panels, - det->n_panels*sizeof(struct panel_template)); + det->panels = cfrealloc(det->panels, + det->n_panels*sizeof(struct panel_template)); new = &det->panels[det->n_panels-1]; memcpy(new, defaults, sizeof(struct panel_template)); /* Set name */ - new->name = strdup(name); + new->name = cfstrdup(name); /* Copy strings */ new->data = safe_strdup(defaults->data); @@ -186,7 +186,7 @@ static struct dt_badregion *new_bad_region(DataTemplate *det, const char *name) struct dt_badregion *new; det->n_bad++; - det->bad = realloc(det->bad, det->n_bad*sizeof(struct dt_badregion)); + det->bad = cfrealloc(det->bad, det->n_bad*sizeof(struct dt_badregion)); new = &det->bad[det->n_bad-1]; new->min_x = NAN; @@ -257,12 +257,12 @@ static int assplode_algebraic(const char *a_orig, char ***pbits) /* Add plus at start if no sign there already */ if ( (a_orig[0] != '+') && (a_orig[0] != '-') ) { len += 1; - a = malloc(len+1); + a = cfmalloc(len+1); snprintf(a, len+1, "+%s", a_orig); a[len] = '\0'; } else { - a = strdup(a_orig); + a = cfstrdup(a_orig); } /* Count the expressions */ @@ -271,7 +271,7 @@ static int assplode_algebraic(const char *a_orig, char ***pbits) if ( (a[i] == '+') || (a[i] == '-') ) nexp++; } - bits = calloc(nexp, sizeof(char *)); + bits = cfcalloc(nexp, sizeof(char *)); /* Break the string up */ idx = -1; @@ -288,7 +288,7 @@ static int assplode_algebraic(const char *a_orig, char ***pbits) if ( (ch == '+') || (ch == '-') ) { if ( idx >= 0 ) bits[idx][istr] = '\0'; idx++; - bits[idx] = malloc(len+1); + bits[idx] = cfmalloc(len+1); istr = 0; } @@ -306,7 +306,7 @@ static int assplode_algebraic(const char *a_orig, char ***pbits) if ( idx >= 0 ) bits[idx][istr] = '\0'; *pbits = bits; - free(a); + cffree(a); return nexp; } @@ -381,10 +381,10 @@ static int dir_conv(const char *a, double *sx, double *sy, double *sz) break; } - free(bits[i]); + cffree(bits[i]); } - free(bits); + cffree(bits); return 0; } @@ -450,7 +450,7 @@ static int parse_mask(struct panel_template *panel, return 1; } - key = strdup(key_orig); + key = cfstrdup(key_orig); if ( key == NULL ) return 1; key[4] = '_'; @@ -459,16 +459,16 @@ static int parse_mask(struct panel_template *panel, * Double underscore is deliberate! */ if ( strcmp(key, "mask__file") == 0 ) { - panel->masks[n].filename = strdup(val); + panel->masks[n].filename = cfstrdup(val); } else if ( strcmp(key, "mask__data") == 0 ) { if ( strncmp(val, "/", 1) != 0 ) { ERROR("Invalid mask location '%s'\n", val); - free(key); + cffree(key); return 1; } - panel->masks[n].data_location = strdup(val); + panel->masks[n].data_location = cfstrdup(val); } else if ( strcmp(key, "mask__goodbits") == 0 ) { @@ -478,7 +478,7 @@ static int parse_mask(struct panel_template *panel, if ( end != val ) { panel->masks[n].good_bits = v; } else { - free(key); + cffree(key); return 1; } @@ -490,19 +490,19 @@ static int parse_mask(struct panel_template *panel, if ( end != val ) { panel->masks[n].bad_bits = v; } else { - free(key); + cffree(key); return 1; } } else { ERROR("Invalid mask directive '%s'\n", key_orig); - free(key); + cffree(key); return 1; } panel->masks[n].mask_default = def; - free(key); + cffree(key); return 0; } @@ -538,8 +538,8 @@ static int parse_field_for_panel(struct panel_template *panel, const char *key, reject = 1; } else if ( strcmp(key, "data") == 0 ) { - free(panel->data); - panel->data = strdup(val); + cffree(panel->data); + panel->data = cfstrdup(val); panel->data_default = def; } else if ( strcmp(key, "mask_edge_pixels") == 0 ) { @@ -563,10 +563,10 @@ static int parse_field_for_panel(struct panel_template *panel, const char *key, reject = parse_mask(panel, key, val, def); } else if ( strcmp(key, "saturation_map") == 0 ) { - panel->satmap = strdup(val); + panel->satmap = cfstrdup(val); panel->satmap_default = def; } else if ( strcmp(key, "saturation_map_file") == 0 ) { - panel->satmap_file = strdup(val); + panel->satmap_file = cfstrdup(val); panel->satmap_file_default = def; } else if ( strcmp(key, "coffset") == 0) { @@ -685,7 +685,7 @@ static int parse_field_bad(struct dt_badregion *badr, const char *key, badr->max_ss = atof(val); reject = check_badr_fsss(badr, 1); } else if ( strcmp(key, "panel") == 0 ) { - badr->panel_name = strdup(val); + badr->panel_name = cfstrdup(val); } else { ERROR("Unrecognised field '%s'\n", key); } @@ -701,13 +701,13 @@ static int parse_electron_voltage(const char *val, char *valcpy; char *sp; - valcpy = strdup(val); + valcpy = cfstrdup(val); if ( valcpy == NULL ) return 1; /* "electron_voltage" directive must have explicit units */ sp = strchr(valcpy, ' '); if ( sp == NULL ) { - free(valcpy); + cffree(valcpy); return 1; } @@ -716,7 +716,7 @@ static int parse_electron_voltage(const char *val, } else if ( strcmp(sp+1, "kV") == 0 ) { *punit = WAVELENGTH_ELECTRON_KV; } else { - free(valcpy); + cffree(valcpy); return 1; } @@ -733,13 +733,13 @@ static int parse_wavelength(const char *val, char *valcpy; char *sp; - valcpy = strdup(val); + valcpy = cfstrdup(val); if ( valcpy == NULL ) return 1; /* "wavelength" directive must have explicit units */ sp = strchr(valcpy, ' '); if ( sp == NULL ) { - free(valcpy); + cffree(valcpy); return 1; } @@ -748,7 +748,7 @@ static int parse_wavelength(const char *val, } else if ( strcmp(sp+1, "A") == 0 ) { *punit = WAVELENGTH_A; } else { - free(valcpy); + cffree(valcpy); return 1; } @@ -765,7 +765,7 @@ static int parse_photon_energy(const char *val, char *valcpy; char *sp; - valcpy = strdup(val); + valcpy = cfstrdup(val); if ( valcpy == NULL ) return 1; /* "photon_energy" is the only one of the wavelength @@ -781,7 +781,7 @@ static int parse_photon_energy(const char *val, sp[0] = '\0'; } else { /* Unit specified, but unrecognised */ - free(valcpy); + cffree(valcpy); return 1; } @@ -819,13 +819,13 @@ static int parse_toplevel(DataTemplate *dt, int *defaults_updated) { if ( strcmp(key, "detector_shift_x") == 0 ) { - dt->shift_x_from = strdup(val); + dt->shift_x_from = cfstrdup(val); } else if ( strcmp(key, "detector_shift_y") == 0 ) { - dt->shift_y_from = strdup(val); + dt->shift_y_from = cfstrdup(val); } else if ( strcmp(key, "clen") == 0 ) { - dt->cnz_from = strdup(val); + dt->cnz_from = cfstrdup(val); } else if ( strcmp(key, "photon_energy") == 0 ) { return parse_photon_energy(val, @@ -843,7 +843,7 @@ static int parse_toplevel(DataTemplate *dt, &dt->wavelength_unit); } else if ( strcmp(key, "peak_list") == 0 ) { - dt->peak_list = strdup(val); + dt->peak_list = cfstrdup(val); } else if ( strcmp(key, "peak_list_type") == 0 ) { return parse_peak_layout(val, &dt->peak_list_type); @@ -1024,7 +1024,7 @@ DataTemplate *data_template_new_from_string(const char *string_in) struct panel_template defaults; int have_unused_defaults = 0; - dt = calloc(1, sizeof(DataTemplate)); + dt = cfcalloc(1, sizeof(DataTemplate)); if ( dt == NULL ) return NULL; dt->n_panels = 0; @@ -1078,7 +1078,7 @@ DataTemplate *data_template_new_from_string(const char *string_in) defaults.satmap_default = 1; defaults.satmap_file = NULL; defaults.satmap_file_default = 1; - defaults.data = strdup("/data/data"); + defaults.data = cfstrdup("/data/data"); defaults.data_default = 1; defaults.name = NULL; defaults.dims[0] = DIM_SS; @@ -1086,7 +1086,7 @@ DataTemplate *data_template_new_from_string(const char *string_in) for ( i=2; i<MAX_DIMS; i++ ) defaults.dims[i] = DIM_UNDEFINED; for ( i=0; i<MAX_DIMS; i++ ) defaults.dims_default[i] = 1; - string = strdup(string_in); + string = cfstrdup(string_in); if ( string == NULL ) return NULL; len = strlen(string); for ( i=0; i<len; i++ ) { @@ -1106,11 +1106,11 @@ DataTemplate *data_template_new_from_string(const char *string_in) const char *nl = strchr(string, '\n'); if ( nl != NULL ) { size_t nlen = nl - string; - line = strndup(string, nlen); + line = cfstrndup(string, nlen); line[nlen] = '\0'; string += nlen+1; } else { - line = strdup(string); + line = cfstrdup(string); done = 1; } @@ -1119,8 +1119,8 @@ DataTemplate *data_template_new_from_string(const char *string_in) char *line_orig = line; while ( (line_orig[i] == ' ') || (line_orig[i] == '\t') ) i++; - line = strdup(line+i); - free(line_orig); + line = cfstrdup(line+i); + cffree(line_orig); /* Stop at comment symbol */ char *comm = strchr(line, ';'); @@ -1129,7 +1129,7 @@ DataTemplate *data_template_new_from_string(const char *string_in) /* Nothing left? Entire line was commented out, * and can be silently ignored */ if ( line[0] == '\0' ) { - free(line); + cffree(line); continue; } @@ -1137,7 +1137,7 @@ DataTemplate *data_template_new_from_string(const char *string_in) char *eq = strchr(line, '='); if ( eq == NULL ) { ERROR("Bad line in geometry file: '%s'\n", line); - free(line); + cffree(line); reject = 1; continue; } @@ -1167,7 +1167,7 @@ DataTemplate *data_template_new_from_string(const char *string_in) line); reject = 1; } - free(line); + cffree(line); continue; } @@ -1195,13 +1195,13 @@ DataTemplate *data_template_new_from_string(const char *string_in) if ( parse_field_bad(badregion, key, val) ) reject = 1; } - free(line); + cffree(line); } while ( !done ); if ( dt->n_panels == 0 ) { ERROR("No panel descriptions in geometry file.\n"); - free(dt); + cffree(dt); return NULL; } @@ -1390,10 +1390,10 @@ DataTemplate *data_template_new_from_string(const char *string_in) } } - free(defaults.data); + cffree(defaults.data); for ( i=0; i<MAX_MASKS; i++ ) { - free(defaults.masks[i].data_location); - free(defaults.masks[i].filename); + cffree(defaults.masks[i].data_location); + cffree(defaults.masks[i].filename); } /* If this is a single-panel detector, there should only be one group @@ -1402,7 +1402,7 @@ DataTemplate *data_template_new_from_string(const char *string_in) parse_group("all", dt, dt->groups[0]->name); } - free(string_orig); + cffree(string_orig); if ( reject ) return NULL; @@ -1422,7 +1422,7 @@ DataTemplate *data_template_new_from_file(const char *filename) } dt = data_template_new_from_string(contents); - free(contents); + cffree(contents); return dt; } @@ -1437,33 +1437,33 @@ void data_template_free(DataTemplate *dt) int j; - free(dt->panels[i].name); - free(dt->panels[i].data); - free(dt->panels[i].satmap); - free(dt->panels[i].satmap_file); + cffree(dt->panels[i].name); + cffree(dt->panels[i].data); + cffree(dt->panels[i].satmap); + cffree(dt->panels[i].satmap_file); for ( j=0; j<MAX_MASKS; j++ ) { - free(dt->panels[i].masks[j].filename); - free(dt->panels[i].masks[j].data_location); + cffree(dt->panels[i].masks[j].filename); + cffree(dt->panels[i].masks[j].data_location); } } for ( i=0; i<dt->n_headers_to_copy; i++ ) { - free(dt->headers_to_copy[i]); + cffree(dt->headers_to_copy[i]); } for ( i=0; i<dt->n_groups; i++ ) { - free(dt->groups[i]->name); - free(dt->groups[i]); + cffree(dt->groups[i]->name); + cffree(dt->groups[i]); } - free(dt->wavelength_from); - free(dt->peak_list); - free(dt->cnz_from); + cffree(dt->wavelength_from); + cffree(dt->peak_list); + cffree(dt->cnz_from); - free(dt->panels); - free(dt->bad); - free(dt); + cffree(dt->panels); + cffree(dt->bad); + cffree(dt); } @@ -1564,7 +1564,7 @@ void data_template_add_copy_header(DataTemplate *dt, return; } - dt->headers_to_copy[dt->n_headers_to_copy++] = strdup(header); + dt->headers_to_copy[dt->n_headers_to_copy++] = cfstrdup(header); } @@ -1682,14 +1682,14 @@ static int separate_value_and_units(const char *from, if ( from == NULL ) return 1; - fromcpy = strdup(from); + fromcpy = cfstrdup(from); if ( fromcpy == NULL ) return 1; sp = strchr(fromcpy, ' '); if ( sp == NULL ) { unitscpy = NULL; } else { - unitscpy = strdup(sp+1); + unitscpy = cfstrdup(sp+1); sp[0] = '\0'; } @@ -1725,14 +1725,14 @@ static int im_get_length(struct image *image, const char *from, if ( convert_float(value_str, pval) == 0 ) { /* Literal value with no units */ - free(value_str); + cffree(value_str); return 0; } else { int r; r = image_read_header_float(image, value_str, pval); - free(value_str); + cffree(value_str); if ( r == 0 ) { /* Value read from headers with no units */ @@ -1756,16 +1756,16 @@ static int im_get_length(struct image *image, const char *from, scale = 1.0; } else { ERROR("Invalid length unit '%s'\n", units); - free(value_str); - free(units); + cffree(value_str); + cffree(units); return 1; } if ( convert_float(value_str, pval) == 0 ) { /* Literal value, units specified */ - free(value_str); - free(units); + cffree(value_str); + cffree(units); *pval *= scale; return 0; @@ -1773,7 +1773,7 @@ static int im_get_length(struct image *image, const char *from, int r; r = image_read_header_float(image, value_str, pval); - free(value_str); + cffree(value_str); if ( r == 0 ) { /* Value read from headers, units specified */ @@ -1849,10 +1849,10 @@ static struct detgeom_panel_group *walk_group(const DataTemplate *dtempl, if ( gt == NULL ) return NULL; - gr = malloc(sizeof(struct detgeom_panel_group)); + gr = cfmalloc(sizeof(struct detgeom_panel_group)); if ( gr == NULL ) return NULL; - gr->name = strdup(gt->name); + gr->name = cfstrdup(gt->name); gr->n_children = gt->n_children; if ( gr->n_children == 0 ) { @@ -1888,9 +1888,9 @@ static struct detgeom_panel_group *walk_group(const DataTemplate *dtempl, double tz = 0.0; gr->panel = NULL; - gr->children = malloc(gt->n_children*sizeof(struct detgeom_panel_group *)); + gr->children = cfmalloc(gt->n_children*sizeof(struct detgeom_panel_group *)); if ( gr->children == NULL ) { - free(gr); + cffree(gr); return NULL; } @@ -1928,14 +1928,14 @@ struct detgeom *create_detgeom(struct image *image, return NULL; } - detgeom = malloc(sizeof(struct detgeom)); + detgeom = cfmalloc(sizeof(struct detgeom)); if ( detgeom == NULL ) return NULL; detgeom->top_group = NULL; - detgeom->panels = malloc(dtempl->n_panels*sizeof(struct detgeom_panel)); + detgeom->panels = cfmalloc(dtempl->n_panels*sizeof(struct detgeom_panel)); if ( detgeom->panels == NULL ) { - free(detgeom); + cffree(detgeom); return NULL; } @@ -1946,8 +1946,8 @@ struct detgeom *create_detgeom(struct image *image, || (dtempl->shift_x_from != NULL) || (dtempl->shift_y_from != NULL) ) { - free(detgeom->panels); - free(detgeom); + cffree(detgeom->panels); + cffree(detgeom); return NULL; } } @@ -2680,7 +2680,7 @@ struct dg_group_info *data_template_group_info(const DataTemplate *dtempl, int * int i; struct panel_group_template *group; - ginfo = malloc(sizeof(struct dg_group_info)*dtempl->n_groups); + ginfo = cfmalloc(sizeof(struct dg_group_info)*dtempl->n_groups); if ( ginfo == NULL ) return NULL; group = find_group(dtempl, "all"); diff --git a/libcrystfel/src/detgeom.c b/libcrystfel/src/detgeom.c index b4835317..39b00663 100644 --- a/libcrystfel/src/detgeom.c +++ b/libcrystfel/src/detgeom.c @@ -74,9 +74,9 @@ static void free_group(struct detgeom_panel_group *g) free_group(g->children[i]); } - free(g->name); - free(g->children); - free(g); + cffree(g->name); + cffree(g->children); + cffree(g); } @@ -87,12 +87,12 @@ void detgeom_free(struct detgeom *detgeom) if ( detgeom == NULL ) return; for ( i=0; i<detgeom->n_panels; i++ ) { - free(detgeom->panels[i].name); + cffree(detgeom->panels[i].name); } free_group(detgeom->top_group); - free(detgeom->panels); - free(detgeom); + cffree(detgeom->panels); + cffree(detgeom); } @@ -250,7 +250,7 @@ gsl_matrix **make_panel_minvs(struct detgeom *dg) int i; gsl_matrix **Minvs; - Minvs = malloc(dg->n_panels * sizeof(gsl_matrix *)); + Minvs = cfmalloc(dg->n_panels * sizeof(gsl_matrix *)); if ( Minvs == NULL ) return NULL; for ( i=0; i<dg->n_panels; i++ ) { diff --git a/libcrystfel/src/filters.c b/libcrystfel/src/filters.c index 4bc41f3d..e3316b1d 100644 --- a/libcrystfel/src/filters.c +++ b/libcrystfel/src/filters.c @@ -136,7 +136,7 @@ void filter_median(struct image *image, int size) nn = nn*nn; /* "localBg" is way too big, but guaranteed big enough */ - buffer = calloc(nn, sizeof(float)); + buffer = cfcalloc(nn, sizeof(float)); if ( buffer == NULL ) { ERROR("Failed to allocate LB buffer.\n"); return; @@ -153,7 +153,7 @@ void filter_median(struct image *image, int size) p = &image->detgeom->panels[pn]; - localBg = calloc(p->w*p->h, sizeof(float)); + localBg = cfcalloc(p->w*p->h, sizeof(float)); if ( localBg == NULL ) { ERROR("Failed to allocate LB buffer.\n"); return; @@ -195,8 +195,8 @@ void filter_median(struct image *image, int size) image->dp[pn][i] -= localBg[i]; } - free(localBg); + cffree(localBg); } - free(buffer); + cffree(buffer); } diff --git a/libcrystfel/src/fom.c b/libcrystfel/src/fom.c index e0149e6e..8c105533 100644 --- a/libcrystfel/src/fom.c +++ b/libcrystfel/src/fom.c @@ -78,14 +78,14 @@ static struct fom_context *init_fom(enum fom_type fom, int nmax, int nshells) struct fom_context *fctx; int i; - fctx = malloc(sizeof(struct fom_context)); + fctx = cfmalloc(sizeof(struct fom_context)); if ( fctx == NULL ) return NULL; fctx->fom = fom; fctx->nshells = nshells; - fctx->cts = malloc(nshells*sizeof(int)); + fctx->cts = cfmalloc(nshells*sizeof(int)); if ( fctx->cts == NULL ) { - free(fctx); + cffree(fctx); return NULL; } for ( i=0; i<nshells; i++ ) { @@ -106,8 +106,8 @@ static struct fom_context *init_fom(enum fom_type fom, int nmax, int nshells) switch ( fctx->fom ) { case FOM_RANORSPLIT : - fctx->num2 = malloc(nshells*sizeof(double)); - fctx->den2 = malloc(nshells*sizeof(double)); + fctx->num2 = cfmalloc(nshells*sizeof(double)); + fctx->den2 = cfmalloc(nshells*sizeof(double)); if ( (fctx->num2 == NULL) || (fctx->den2 == NULL) ) goto out; for ( i=0; i<nshells; i++ ) { fctx->num2[i] = 0.0; @@ -123,8 +123,8 @@ static struct fom_context *init_fom(enum fom_type fom, int nmax, int nshells) case FOM_MEAN_INTENSITY : case FOM_SNR : case FOM_REDUNDANCY : - fctx->num = malloc(nshells*sizeof(double)); - fctx->den = malloc(nshells*sizeof(double)); + fctx->num = cfmalloc(nshells*sizeof(double)); + fctx->den = cfmalloc(nshells*sizeof(double)); if ( (fctx->num == NULL) || (fctx->den == NULL) ) goto out; for ( i=0; i<nshells; i++ ) { fctx->num[i] = 0.0; @@ -137,7 +137,7 @@ static struct fom_context *init_fom(enum fom_type fom, int nmax, int nshells) break; case FOM_NUM_MEASUREMENTS : - fctx->n_meas = calloc(nshells, sizeof(long int)); + fctx->n_meas = cfcalloc(nshells, sizeof(long int)); if ( fctx->n_meas == NULL ) goto out; break; @@ -145,20 +145,20 @@ static struct fom_context *init_fom(enum fom_type fom, int nmax, int nshells) case FOM_CCSTAR : case FOM_CCANO : case FOM_CRDANO : - fctx->vec1 = malloc(nshells*sizeof(double *)); - fctx->vec2 = malloc(nshells*sizeof(double *)); + fctx->vec1 = cfmalloc(nshells*sizeof(double *)); + fctx->vec2 = cfmalloc(nshells*sizeof(double *)); if ( (fctx->vec1 == NULL) || (fctx->vec2 == NULL) ) goto out; for ( i=0; i<nshells; i++ ) { fctx->vec1[i] = NULL; fctx->vec2[i] = NULL; } for ( i=0; i<nshells; i++ ) { - fctx->vec1[i] = malloc(nmax*sizeof(double)); + fctx->vec1[i] = cfmalloc(nmax*sizeof(double)); if ( fctx->vec1[i] == NULL ) goto out; - fctx->vec2[i] = malloc(nmax*sizeof(double)); + fctx->vec2[i] = cfmalloc(nmax*sizeof(double)); if ( fctx->vec2[i] == NULL ) goto out; } - fctx->n = malloc(nshells*sizeof(int)); + fctx->n = cfmalloc(nshells*sizeof(int)); if ( fctx->n == NULL ) goto out; for ( i=0; i<nshells; i++ ) { fctx->n[i] = 0; @@ -168,7 +168,7 @@ static struct fom_context *init_fom(enum fom_type fom, int nmax, int nshells) case FOM_D1SIG : case FOM_D2SIG : - fctx->n_within = malloc(nshells*sizeof(int)); + fctx->n_within = cfmalloc(nshells*sizeof(int)); if ( fctx->n_within == NULL ) goto out; for ( i=0; i<nshells; i++ ) { fctx->n_within[i] = 0; @@ -180,26 +180,26 @@ static struct fom_context *init_fom(enum fom_type fom, int nmax, int nshells) return fctx; out: - free(fctx->num2); - free(fctx->den2); - free(fctx->num); - free(fctx->den); - free(fctx->n_meas); + cffree(fctx->num2); + cffree(fctx->den2); + cffree(fctx->num); + cffree(fctx->den); + cffree(fctx->n_meas); if ( fctx->vec1 != NULL ) { for ( i=0; i<nshells; i++ ) { - free(fctx->vec1[i]); + cffree(fctx->vec1[i]); } - free(fctx->vec1); + cffree(fctx->vec1); } if ( fctx->vec2 != NULL ) { for ( i=0; i<nshells; i++ ) { - free(fctx->vec2[i]); + cffree(fctx->vec2[i]); } - free(fctx->vec2); + cffree(fctx->vec2); } - free(fctx->n); - free(fctx->n_within); - free(fctx); + cffree(fctx->n); + cffree(fctx->n_within); + cffree(fctx); return NULL; } @@ -404,8 +404,8 @@ double fom_overall_value(struct fom_context *fctx) case FOM_CC : case FOM_CCSTAR : case FOM_CCANO : - overall_vec1 = malloc(fctx->nmax*sizeof(double)); - overall_vec2 = malloc(fctx->nmax*sizeof(double)); + overall_vec1 = cfmalloc(fctx->nmax*sizeof(double)); + overall_vec2 = cfmalloc(fctx->nmax*sizeof(double)); overall_n = 0; for ( i=0; i<fctx->nshells; i++ ) { int j; @@ -417,13 +417,13 @@ double fom_overall_value(struct fom_context *fctx) } cc = gsl_stats_correlation(overall_vec1, 1, overall_vec2, 1, overall_n); - free(overall_vec1); - free(overall_vec2); + cffree(overall_vec1); + cffree(overall_vec2); break; case FOM_CRDANO : - overall_along_diagonal = malloc(fctx->nmax*sizeof(double)); - overall_perpend_diagonal = malloc(fctx->nmax*sizeof(double)); + overall_along_diagonal = cfmalloc(fctx->nmax*sizeof(double)); + overall_perpend_diagonal = cfmalloc(fctx->nmax*sizeof(double)); overall_n = 0; for ( i=0; i<fctx->nshells; i++ ) { int j; @@ -443,8 +443,8 @@ double fom_overall_value(struct fom_context *fctx) 1, overall_n, 0.0); cc = sqrt(variance_signal / variance_error ); - free(overall_along_diagonal); - free(overall_perpend_diagonal); + cffree(overall_along_diagonal); + cffree(overall_perpend_diagonal); break; case FOM_D1SIG : @@ -566,8 +566,8 @@ double fom_shell_value(struct fom_context *fctx, int i) (2.0*(fctx->num2[i]/fctx->den2[i]) / sqrt(2.0)); case FOM_CRDANO : - along_diagonal = malloc(fctx->n[i] * sizeof(double)); - perpend_diagonal = malloc(fctx->n[i] * sizeof(double)); + along_diagonal = cfmalloc(fctx->n[i] * sizeof(double)); + perpend_diagonal = cfmalloc(fctx->n[i] * sizeof(double)); for ( j=0; j<fctx->n[i]; j++ ) { along_diagonal[j] = ( fctx->vec1[i][j] + fctx->vec2[i][j] ) / sqrt(2.0); @@ -578,8 +578,8 @@ double fom_shell_value(struct fom_context *fctx, int i) fctx->n[i], 0.0); variance_error = gsl_stats_variance_m(perpend_diagonal, 1, fctx->n[i], 0.0); - free(along_diagonal); - free(perpend_diagonal); + cffree(along_diagonal); + cffree(perpend_diagonal); return sqrt(variance_signal / variance_error); case FOM_D1SIG : @@ -616,17 +616,17 @@ struct fom_shells *fom_make_resolution_shells(double rmin, double rmax, double total_vol, vol_per_shell; int i; - s = malloc(sizeof(struct fom_shells)); + s = cfmalloc(sizeof(struct fom_shells)); if ( s == NULL ) return NULL; - s->rmins = malloc(nshells*sizeof(double)); - s->rmaxs = malloc(nshells*sizeof(double)); + s->rmins = cfmalloc(nshells*sizeof(double)); + s->rmaxs = cfmalloc(nshells*sizeof(double)); if ( (s->rmins==NULL) || (s->rmaxs==NULL) ) { ERROR("Couldn't allocate memory for resolution shells.\n"); - free(s->rmins); - free(s->rmaxs); - free(s); + cffree(s->rmins); + cffree(s->rmaxs); + cffree(s); return NULL; } @@ -705,8 +705,8 @@ static int wilson_scale(RefList *list1, RefList *list2, UnitCell *cell) double G, B; double c0, c1, cov00, cov01, cov11, chisq; - x = malloc(max_n*sizeof(double)); - y = malloc(max_n*sizeof(double)); + x = cfmalloc(max_n*sizeof(double)); + y = cfmalloc(max_n*sizeof(double)); if ( (x==NULL) || (y==NULL) ) { ERROR("Failed to allocate memory for scaling.\n"); return 1; @@ -772,8 +772,8 @@ static int wilson_scale(RefList *list1, RefList *list2, UnitCell *cell) STATUS("A positive relative B factor means that the second reflection " "list falls off with resolution more quickly than the first.\n"); - free(x); - free(y); + cffree(x); + cffree(y); /* Apply the scaling factor */ for ( refl2 = first_refl(list2, &iter); @@ -808,12 +808,12 @@ static int calculate_possible(struct fom_context *fctx, double cx, cy, cz; signed int h, k, l; - fctx->possible = calloc(fctx->nshells, sizeof(long int)); + fctx->possible = cfcalloc(fctx->nshells, sizeof(long int)); if ( fctx->possible == NULL ) return 1; counted = reflist_new(); if ( counted == NULL ) { - free(fctx->possible); + cffree(fctx->possible); return 1; } diff --git a/libcrystfel/src/image-cbf.c b/libcrystfel/src/image-cbf.c index 0fb3b61c..c0e38283 100644 --- a/libcrystfel/src/image-cbf.c +++ b/libcrystfel/src/image-cbf.c @@ -302,7 +302,7 @@ static float *read_cbf_data(const char *filename, int gz, int *w, int *h) gzbuffer(gzfh, 128*1024); #endif - buf = malloc(bufsz); + buf = cfmalloc(bufsz); if ( buf == NULL ) return NULL; len = 0; @@ -322,7 +322,7 @@ static float *read_cbf_data(const char *filename, int gz, int *w, int *h) fh = fmemopen(buf, len, "rb"); if ( fh == NULL ) { - free(buf); + cffree(buf); return NULL; } @@ -365,7 +365,7 @@ static float *read_cbf_data(const char *filename, int gz, int *w, int *h) const char *elbo = line+29; if ( strcmp(elbo, "LITTLE_ENDIAN") != 0 ) { ERROR("Unsupported endianness: %s\n", elbo); - free(buf); + cffree(buf); fclose(fh); return NULL; } @@ -380,7 +380,7 @@ static float *read_cbf_data(const char *filename, int gz, int *w, int *h) data_conversion = CBF_PACKED; } else if ( strstr(line, "conversions=") != NULL ) { ERROR("Unrecognised CBF content conversion: %s\n", line); - free(buf); + cffree(buf); fclose(fh); return NULL; } @@ -393,7 +393,7 @@ static float *read_cbf_data(const char *filename, int gz, int *w, int *h) if ( data_type == CBF_NO_TYPE ) { ERROR("Unrecognised element type: %s\n", eltype); - free(buf); + cffree(buf); fclose(fh); return NULL; } @@ -418,29 +418,29 @@ static float *read_cbf_data(const char *filename, int gz, int *w, int *h) if ( data_compressed_len == 0 ) { ERROR("Found CBF data before X-Binary-Size!\n"); - free(buf); + cffree(buf); fclose(fh); return NULL; } if ( (*w == 0) || (*h == 0) ) { ERROR("Found CBF data before dimensions!\n"); - free(buf); + cffree(buf); fclose(fh); return NULL; } if ( data_compressed_len > 100*1024*1024 ) { ERROR("Stated CBF data size too big\n"); - free(buf); + cffree(buf); fclose(fh); return NULL; } - data_compressed = malloc(data_compressed_len); + data_compressed = cfmalloc(data_compressed_len); if ( data_compressed == NULL ) { ERROR("Failed to allocate memory for CBF data\n"); - free(buf); + cffree(buf); fclose(fh); return NULL; } @@ -449,18 +449,18 @@ static float *read_cbf_data(const char *filename, int gz, int *w, int *h) len_read = fread(data_compressed, 1, data_compressed_len, fh); if ( len_read < data_compressed_len ) { ERROR("Couldn't read entire CBF data\n"); - free(buf); - free(data_compressed); + cffree(buf); + cffree(data_compressed); fclose(fh); return NULL; } nmemb_exp = (*w) * (*h); - data_out = malloc(nmemb_exp*sizeof(float)); + data_out = cfmalloc(nmemb_exp*sizeof(float)); if ( data_out == NULL ) { ERROR("Failed to allocate memory for CBF data\n"); - free(buf); - free(data_compressed); + cffree(buf); + cffree(data_compressed); fclose(fh); return NULL; } @@ -483,23 +483,23 @@ static float *read_cbf_data(const char *filename, int gz, int *w, int *h) case CBF_CANONICAL: ERROR("Don't yet know how to decompress " "CBF_PACKED or CBF_CANONICAL\n"); - free(buf); - free(data_compressed); + cffree(buf); + cffree(data_compressed); fclose(fh); return NULL; } - free(data_compressed); + cffree(data_compressed); if ( r ) { - free(buf); - free(data_out); + cffree(buf); + cffree(data_out); fclose(fh); return NULL; } - free(buf); + cffree(buf); fclose(fh); return data_out; @@ -508,7 +508,7 @@ static float *read_cbf_data(const char *filename, int gz, int *w, int *h) } while ( rval != NULL ); ERROR("Reached end of CBF file before finding data.\n"); - free(buf); /* might be NULL */ + cffree(buf); /* might be NULL */ return NULL; } @@ -598,7 +598,7 @@ int image_cbf_read(struct image *image, ERROR("Failed to read CBF data\n"); return 1; } - free(data); + cffree(data); //cbf_fill_in_beam_parameters(image->beam, f, image); //cbf_fill_in_clen(image->det, f); diff --git a/libcrystfel/src/image-hdf5.c b/libcrystfel/src/image-hdf5.c index 37d333ac..a148c307 100644 --- a/libcrystfel/src/image-hdf5.c +++ b/libcrystfel/src/image-hdf5.c @@ -60,7 +60,7 @@ char **read_path_parts(const char *ev_orig, int *pn_plvals) int n_plvals = 0; char *start; - plvals = malloc(MAX_PATH_PARTS*sizeof(char *)); + plvals = cfmalloc(MAX_PATH_PARTS*sizeof(char *)); if ( plvals == NULL ) return NULL; if ( ev_orig == NULL ) { @@ -69,9 +69,9 @@ char **read_path_parts(const char *ev_orig, int *pn_plvals) return plvals; } - ev = strdup(ev_orig); + ev = cfstrdup(ev_orig); if ( ev == NULL ) { - free(plvals); + cffree(plvals); return NULL; } @@ -87,8 +87,8 @@ char **read_path_parts(const char *ev_orig, int *pn_plvals) * must at least have // */ ERROR("Couldn't read path parts ('%s')\n", start); - free(ev); - free(plvals); + cffree(ev); + cffree(plvals); return NULL; } @@ -97,19 +97,19 @@ char **read_path_parts(const char *ev_orig, int *pn_plvals) if ( n_plvals == MAX_PATH_PARTS ) { ERROR("Too many path parts: %s\n", ev_orig); - free(ev); - free(plvals); + cffree(ev); + cffree(plvals); return NULL; } sep[0] = '\0'; - plvals[n_plvals++] = strdup(start); + plvals[n_plvals++] = cfstrdup(start); start = sep+1; } while ( 1 ); - free(ev); + cffree(ev); *pn_plvals = n_plvals; return plvals; } @@ -135,7 +135,7 @@ int *read_dim_parts(const char *ev_orig, int *pn_dvals) ev = strstr(ev_orig, "//"); if ( ev == NULL ) return NULL; - dvals = malloc(MAX_DIMS*sizeof(int)); + dvals = cfmalloc(MAX_DIMS*sizeof(int)); if ( dvals == NULL ) return NULL; if ( ev[2] == '\0' ) { @@ -144,9 +144,9 @@ int *read_dim_parts(const char *ev_orig, int *pn_dvals) return dvals; /* NB Not NULL */ } - ev = strdup(ev+2); + ev = cfstrdup(ev+2); if ( ev == NULL ) { - free(dvals); + cffree(dvals); return NULL; } @@ -164,15 +164,15 @@ int *read_dim_parts(const char *ev_orig, int *pn_dvals) if ( n_dvals == MAX_PATH_PARTS ) { ERROR("Too many path parts: %s\n", ev_orig); - free(ev); - free(dvals); + cffree(ev); + cffree(dvals); return NULL; } if ( start[0] == '\0' ) { ERROR("Missing dimension: %s\n", ev_orig); - free(ev); - free(dvals); + cffree(ev); + cffree(dvals); return NULL; } @@ -182,7 +182,7 @@ int *read_dim_parts(const char *ev_orig, int *pn_dvals) } while ( !done ); - free(ev); + cffree(ev); *pn_dvals = n_dvals; return dvals; } @@ -247,19 +247,19 @@ char *substitute_path(const char *ev, const char *pattern, int skip_ok) if ( n_pl_exp == 0 ) { /* No placeholders in path */ for ( i=0; i<n_plvals; i++ ) { - free(plvals[i]); + cffree(plvals[i]); } - free(plvals); - return strdup(pattern); + cffree(plvals); + return cfstrdup(pattern); } total_len = strlen(pattern) - n_pl_exp; for ( i=0; i<n_plvals; i++ ) { total_len += strlen(plvals[i]); } - subs = malloc(total_len+1); + subs = cfmalloc(total_len+1); if ( subs == NULL ) { - free(plvals); + cffree(plvals); return NULL; } @@ -277,7 +277,7 @@ char *substitute_path(const char *ev, const char *pattern, int skip_ok) /* Add the placeholder's value */ strcat(subs, plvals[i]); - free(plvals[i]); + cffree(plvals[i]); /* Add the chars up to the next placeholder... */ pl_pos = strchr(start, '%'); @@ -289,7 +289,7 @@ char *substitute_path(const char *ev, const char *pattern, int skip_ok) start = pl_pos+1; } - free(plvals); + cffree(plvals); return subs; } @@ -400,12 +400,12 @@ static int load_hdf5_hyperslab(struct panel_template *p, ERROR("Cannot open data for panel %s (%s)\n", p->name, panel_full_path); profile_end("H5Dopen2"); - free(panel_full_path); + cffree(panel_full_path); return 1; } profile_end("H5Dopen2"); - free(panel_full_path); + cffree(panel_full_path); /* Set up dataspace for file * (determine where to read the data from) */ @@ -446,12 +446,12 @@ static int load_hdf5_hyperslab(struct panel_template *p, n_dt_dims = total_dt_dims; } - f_offset = malloc(ndims*sizeof(hsize_t)); - f_count = malloc(ndims*sizeof(hsize_t)); + f_offset = cfmalloc(ndims*sizeof(hsize_t)); + f_count = cfmalloc(ndims*sizeof(hsize_t)); if ( (f_offset == NULL) || (f_count == NULL ) ) { ERROR("Failed to allocate offset or count.\n"); - free(f_offset); - free(f_count); + cffree(f_offset); + cffree(f_count); H5Dclose(dh); return 1; } @@ -492,15 +492,15 @@ static int load_hdf5_hyperslab(struct panel_template *p, } } - free(dim_vals); + cffree(dim_vals); check = H5Sselect_hyperslab(dataspace, H5S_SELECT_SET, f_offset, NULL, f_count, NULL); if ( check < 0 ) { ERROR("Error selecting file dataspace for panel %s\n", p->name); - free(f_offset); - free(f_count); + cffree(f_offset); + cffree(f_count); H5Dclose(dh); return 1; } @@ -515,15 +515,15 @@ static int load_hdf5_hyperslab(struct panel_template *p, if ( r < 0 ) { ERROR("Couldn't read data for panel %s\n", p->name); - free(f_offset); - free(f_count); - free(data); + cffree(f_offset); + cffree(f_count); + cffree(data); H5Dclose(dh); return 1; } - free(f_offset); - free(f_count); + cffree(f_offset); + cffree(f_count); if ( orig_type != NULL ) { *orig_type = H5Dget_type(dh); @@ -679,7 +679,7 @@ int image_hdf5_read_mask(struct panel_template *p, return 1; } - mask = malloc(p_w*p_h*sizeof(int)); + mask = cfmalloc(p_w*p_h*sizeof(int)); if ( mask == NULL ) return 1; if ( load_hdf5_hyperslab(p, fh, event, @@ -687,7 +687,7 @@ int image_hdf5_read_mask(struct panel_template *p, sizeof(int), 1, mask_location, NULL) ) { ERROR("Failed to load mask data\n"); - free(mask); + cffree(mask); return 1; } @@ -703,7 +703,7 @@ int image_hdf5_read_mask(struct panel_template *p, } - free(mask); + cffree(mask); return 0; } @@ -724,7 +724,7 @@ static char *read_single_fixed_string(hid_t dh) sh = H5Screate(H5S_SCALAR); type = H5Dget_type(dh); size = H5Tget_size(type); - tmp = malloc(size+1); + tmp = cfmalloc(size+1); if ( tmp == NULL ) { H5Tclose(type); return NULL; @@ -733,7 +733,7 @@ static char *read_single_fixed_string(hid_t dh) H5Sclose(sh); H5Tclose(type); if ( r < 0 ) { - free(tmp); + cffree(tmp); ERROR("Couldn't read scalar string\n"); return NULL; } else { @@ -802,7 +802,7 @@ int image_hdf5_read_header_to_cache(struct image *image, const char *name) dh = H5Dopen2(fh, subst_name, H5P_DEFAULT); if ( dh < 0 ) { ERROR("No such numeric field '%s'\n", subst_name); - free(subst_name); + cffree(subst_name); close_hdf5(fh); return 1; } @@ -822,7 +822,7 @@ int image_hdf5_read_header_to_cache(struct image *image, const char *name) ERROR("HDF5 header is not a recognised type (%s).\n", subst_name); close_hdf5(fh); - free(subst_name); + cffree(subst_name); return 1; } @@ -833,7 +833,7 @@ int image_hdf5_read_header_to_cache(struct image *image, const char *name) if ( ndims > 64 ) { ERROR("Too many dimensions for numeric value\n"); close_hdf5(fh); - free(subst_name); + cffree(subst_name); return 1; } H5Sget_simple_extent_dims(sh, size, NULL); @@ -855,12 +855,12 @@ int image_hdf5_read_header_to_cache(struct image *image, const char *name) if ( r < 0 ) { ERROR("Couldn't read scalar value from %s.\n", subst_name); - free(subst_name); + cffree(subst_name); close_hdf5(fh); return 1; } image_cache_header_float(image, name, val); - free(subst_name); + cffree(subst_name); return 0; } else if ( class == H5T_INTEGER ) { @@ -871,12 +871,12 @@ int image_hdf5_read_header_to_cache(struct image *image, const char *name) if ( r < 0 ) { ERROR("Couldn't read scalar value from %s.\n", subst_name); - free(subst_name); + cffree(subst_name); close_hdf5(fh); return 1; } image_cache_header_int(image, name, val); - free(subst_name); + cffree(subst_name); return 0; } else if ( class == H5T_STRING ) { @@ -902,7 +902,7 @@ int image_hdf5_read_header_to_cache(struct image *image, const char *name) if ( val != NULL ) { image_cache_header_str(image, name, val); - free(val); + cffree(val); rv = 0; } else { ERROR("Failed to read string '%s'\n", @@ -910,14 +910,14 @@ int image_hdf5_read_header_to_cache(struct image *image, const char *name) rv = 1; } - free(subst_name); + cffree(subst_name); close_hdf5(fh); return rv; } else { /* Should never be reached */ ERROR("Invalid HDF5 class %i\n", class); - free(subst_name); + cffree(subst_name); return 1; } } @@ -926,16 +926,16 @@ int image_hdf5_read_header_to_cache(struct image *image, const char *name) if ( dim_vals == NULL ) { ERROR("Couldn't parse event '%s'\n"); close_hdf5(fh); - free(subst_name); + cffree(subst_name); return 1; } - f_offset = malloc(ndims*sizeof(hsize_t)); - f_count = malloc(ndims*sizeof(hsize_t)); + f_offset = cfmalloc(ndims*sizeof(hsize_t)); + f_count = cfmalloc(ndims*sizeof(hsize_t)); if ( (f_offset == NULL) || (f_count == NULL) ) { ERROR("Couldn't allocate dimension arrays\n"); close_hdf5(fh); - free(subst_name); + cffree(subst_name); return 1; } @@ -953,8 +953,8 @@ int image_hdf5_read_header_to_cache(struct image *image, const char *name) subst_name, i, dim_vals[dim_val_pos], size[i]); close_hdf5(fh); - free(subst_name); - free(dim_vals); + cffree(subst_name); + cffree(dim_vals); return 1; } @@ -970,21 +970,21 @@ int image_hdf5_read_header_to_cache(struct image *image, const char *name) } } - free(dim_vals); + cffree(dim_vals); check = H5Sselect_hyperslab(sh, H5S_SELECT_SET, f_offset, NULL, f_count, NULL); if ( check < 0 ) { ERROR("Error selecting dataspace for header value\n"); - free(f_offset); - free(f_count); - free(subst_name); + cffree(f_offset); + cffree(f_count); + cffree(subst_name); close_hdf5(fh); return 1; } - free(f_offset); - free(f_count); + cffree(f_offset); + cffree(f_count); ms = H5Screate_simple(1,msdims,NULL); check = H5Sselect_hyperslab(ms, H5S_SELECT_SET, @@ -992,7 +992,7 @@ int image_hdf5_read_header_to_cache(struct image *image, const char *name) if ( check < 0 ) { ERROR("Error selecting memory dataspace for header value\n"); close_hdf5(fh); - free(subst_name); + cffree(subst_name); return 1; } @@ -1003,13 +1003,13 @@ int image_hdf5_read_header_to_cache(struct image *image, const char *name) if ( r < 0 ) { ERROR("Couldn't read value.\n"); close_hdf5(fh); - free(subst_name); + cffree(subst_name); return 1; } image_cache_header_float(image, name, val); close_hdf5(fh); - free(subst_name); + cffree(subst_name); return 0; } else if ( class == H5T_INTEGER ) { @@ -1019,13 +1019,13 @@ int image_hdf5_read_header_to_cache(struct image *image, const char *name) if ( r < 0 ) { ERROR("Couldn't read value.\n"); close_hdf5(fh); - free(subst_name); + cffree(subst_name); return 1; } image_cache_header_int(image, name, val); close_hdf5(fh); - free(subst_name); + cffree(subst_name); return 0; } else if ( class == H5T_STRING ) { @@ -1044,16 +1044,16 @@ int image_hdf5_read_header_to_cache(struct image *image, const char *name) if ( rv < 0 ) { ERROR("Can't read HDF5 vlen string from array - %s\n", subst_name); - free(subst_name); + cffree(subst_name); close_hdf5(fh); return 1; } else { chomp(val); image_cache_header_str(image, name, val); - free(val); + cffree(val); close_hdf5(fh); - free(subst_name); + cffree(subst_name); return 0; } @@ -1066,10 +1066,10 @@ int image_hdf5_read_header_to_cache(struct image *image, const char *name) size_t ssize; ssize = H5Tget_size(stype); - val = malloc(ssize+1); + val = cfmalloc(ssize+1); if ( val == NULL ) { close_hdf5(fh); - free(subst_name); + cffree(subst_name); return 1; } rv = H5Dread(dh, stype, ms, sh, H5P_DEFAULT, val); @@ -1078,16 +1078,16 @@ int image_hdf5_read_header_to_cache(struct image *image, const char *name) ERROR("Couldn't read HDF5 fixed string from array - %s\n", subst_name); close_hdf5(fh); - free(subst_name); + cffree(subst_name); return 1; } else { val[ssize] = '\0'; chomp(val); image_cache_header_str(image, name, val); - free(val); + cffree(val); close_hdf5(fh); - free(subst_name); + cffree(subst_name); return 0; } @@ -1098,7 +1098,7 @@ int image_hdf5_read_header_to_cache(struct image *image, const char *name) /* Should never be reached */ ERROR("Invalid HDF5 class %i\n", class); close_hdf5(fh); - free(subst_name); + cffree(subst_name); return 1; } } @@ -1279,7 +1279,7 @@ static float *read_peak_line(hid_t fh, char *path, int line, return NULL; } - buf = malloc(size[1]*sizeof(float)); + buf = cfmalloc(size[1]*sizeof(float)); if ( buf == NULL ) return NULL; r = H5Dread(dh, H5T_NATIVE_FLOAT, mh, sh, H5P_DEFAULT, buf); if ( r < 0 ) { @@ -1336,19 +1336,19 @@ ImageFeatureList *image_hdf5_read_peaks_cxi(const DataTemplate *dtempl, dim_vals = read_dim_parts(event, &n_dim_vals); if ( dim_vals == NULL ) { ERROR("Couldn't parse event '%s'\n"); - free(subst_name); + cffree(subst_name); return NULL; } if ( n_dim_vals < 1 ) { ERROR("Not enough dimensions in event ID to use CXI " "peak lists (%i)\n", n_dim_vals); - free(subst_name); + cffree(subst_name); return NULL; } line = dim_vals[0]; - free(dim_vals); + cffree(dim_vals); snprintf(path_n, 1024, "%s/nPeaks", subst_name); snprintf(path_x, 1024, "%s/peakXPosRaw", subst_name); @@ -1358,37 +1358,37 @@ ImageFeatureList *image_hdf5_read_peaks_cxi(const DataTemplate *dtempl, fh = H5Fopen(filename, H5F_ACC_RDONLY, H5P_DEFAULT); if ( fh < 0 ) { ERROR("Couldn't open file (peaks/cxi): %s\n", filename); - free(subst_name); + cffree(subst_name); return NULL; } r = read_peak_count(fh, path_n, line, &num_peaks); if ( r != 0 ) { close_hdf5(fh); - free(subst_name); + cffree(subst_name); return NULL; } buf_x = read_peak_line(fh, path_x, line, num_peaks); if ( buf_x == NULL ) { close_hdf5(fh); - free(subst_name); + cffree(subst_name); return NULL; } buf_y = read_peak_line(fh, path_y, line, num_peaks); if ( buf_y == NULL ) { - free(buf_x); - free(subst_name); + cffree(buf_x); + cffree(subst_name); close_hdf5(fh); return NULL; } buf_i = read_peak_line(fh, path_i, line, num_peaks); if ( buf_i == NULL ) { - free(buf_x); - free(buf_y); - free(subst_name); + cffree(buf_x); + cffree(buf_y); + cffree(subst_name); close_hdf5(fh); return NULL; } @@ -1415,10 +1415,10 @@ ImageFeatureList *image_hdf5_read_peaks_cxi(const DataTemplate *dtempl, } - free(buf_x); - free(buf_y); - free(buf_i); - free(subst_name); + cffree(buf_x); + cffree(buf_y); + cffree(buf_i); + cffree(subst_name); close_hdf5(fh); @@ -1470,11 +1470,11 @@ ImageFeatureList *image_hdf5_read_peaks_hdf5(const DataTemplate *dtempl, dh = H5Dopen2(fh, subst_name, H5P_DEFAULT); if ( dh < 0 ) { ERROR("Peak list (%s) not found.\n", subst_name); - free(subst_name); + cffree(subst_name); close_hdf5(fh); return NULL; } - free(subst_name); + cffree(subst_name); sh = H5Dget_space(dh); if ( sh < 0 ) { @@ -1500,7 +1500,7 @@ ImageFeatureList *image_hdf5_read_peaks_hdf5(const DataTemplate *dtempl, return NULL; } - buf = malloc(sizeof(float)*size[0]*size[1]); + buf = cfmalloc(sizeof(float)*size[0]*size[1]); if ( buf == NULL ) { ERROR("Couldn't reserve memory for the peak list.\n"); close_hdf5(fh); @@ -1541,7 +1541,7 @@ ImageFeatureList *image_hdf5_read_peaks_hdf5(const DataTemplate *dtempl, } - free(buf); + cffree(buf); close_hdf5(fh); return features; @@ -1555,7 +1555,7 @@ static char *matches_pattern(const char *name, const char *pattern, const char *ev_str_old) { if ( strcmp(pattern, "%") == 0 ) { - char *nstr = malloc(strlen(ev_str_old)+strlen(name)+2); + char *nstr = cfmalloc(strlen(ev_str_old)+strlen(name)+2); if ( nstr == NULL ) { ERROR("Couldn't allocate memory\n"); return NULL; @@ -1566,7 +1566,7 @@ static char *matches_pattern(const char *name, const char *pattern, return nstr; } else { if ( strcmp(name, pattern) == 0 ) { - return strdup(ev_str_old); + return cfstrdup(ev_str_old); } else { return NULL; } @@ -1586,14 +1586,14 @@ struct ev_list static int add_ev_to_list(struct ev_list *list, char *ev_str) { if ( list->n_events == list->max_events ) { - char **new_events = realloc(list->events, - (list->max_events+128)*sizeof(char *)); + char **new_events = cfrealloc(list->events, + (list->max_events+128)*sizeof(char *)); if ( new_events == NULL ) return 1; list->max_events += 128; list->events = new_events; } - list->events[list->n_events++] = strdup(ev_str); + list->events[list->n_events++] = cfstrdup(ev_str); return 0; } @@ -1604,9 +1604,9 @@ static char *demunge_event(const char *orig) size_t len = strlen(orig); char *slash; - if ( len == 0 ) return strdup("//"); + if ( len == 0 ) return cfstrdup("//"); - slash = malloc(len+3); + slash = cfmalloc(len+3); if ( slash == NULL ) return NULL; strcpy(slash, orig+1); strcat(slash, "//"); @@ -1641,7 +1641,7 @@ static int rec_expand_paths(hid_t gh, struct ev_list *list, return 1; } - name = malloc(size+1); + name = cfmalloc(size+1); if ( name == NULL ) { ERROR("Couldn't allocate memory\n"); return 1; @@ -1658,7 +1658,7 @@ static int rec_expand_paths(hid_t gh, struct ev_list *list, ev_str_new = matches_pattern(name, pattern_bits[0], ev_str); if ( ev_str_new == NULL ) { - free(name); + cffree(name); continue; } @@ -1666,8 +1666,8 @@ static int rec_expand_paths(hid_t gh, struct ev_list *list, H5_ITER_INC, i, &obj_info, 0) < 0 ) { ERROR("Couldn't get info\n"); - free(name); - free(ev_str_new); + cffree(name); + cffree(ev_str_new); return 1; } @@ -1678,16 +1678,16 @@ static int rec_expand_paths(hid_t gh, struct ev_list *list, if ( n_pattern_bits == 1 ) { ERROR("Pattern doesn't match file" " (too short)\n"); - free(name); - free(ev_str_new); + cffree(name); + cffree(ev_str_new); return 1; } child_gh = H5Gopen1(gh, name); if ( child_gh < 0 ) { ERROR("Couldn't open '%s'\n", name); - free(name); - free(ev_str_new); + cffree(name); + cffree(ev_str_new); return 1; } @@ -1696,12 +1696,12 @@ static int rec_expand_paths(hid_t gh, struct ev_list *list, &pattern_bits[1], n_pattern_bits - 1) ) { - free(name); - free(ev_str_new); + cffree(name); + cffree(ev_str_new); return 1; } - free(ev_str_new); + cffree(ev_str_new); H5Gclose(child_gh); } else if ( obj_info.type == H5O_TYPE_DATASET ) { @@ -1712,21 +1712,21 @@ static int rec_expand_paths(hid_t gh, struct ev_list *list, ERROR("Pattern doesn't match file" " (too long by %i)\n", n_pattern_bits); - free(name); - free(ev_str_new); + cffree(name); + cffree(ev_str_new); return 1; } addme = demunge_event(ev_str_new); if ( addme != NULL ) { add_ev_to_list(list, addme); - free(addme); + cffree(addme); } - free(ev_str_new); + cffree(ev_str_new); } - free(name); + cffree(name); } @@ -1755,7 +1755,7 @@ char **expand_paths(hid_t fh, char *pattern, int *n_evs) if ( pattern[i] == '/' ) n_sep++; } - pattern_bits = malloc(n_sep*sizeof(char *)); + pattern_bits = cfmalloc(n_sep*sizeof(char *)); if ( pattern_bits == NULL ) return NULL; start = pattern+1; @@ -1764,7 +1764,7 @@ char **expand_paths(hid_t fh, char *pattern, int *n_evs) if ( sep == NULL ) { sep = start+strlen(start); } - pattern_bits[i] = strndup(start, sep-start); + pattern_bits[i] = cfstrndup(start, sep-start); if ( pattern_bits[i] == NULL ) return NULL; start = sep+1; } @@ -1776,9 +1776,9 @@ char **expand_paths(hid_t fh, char *pattern, int *n_evs) rec_expand_paths(fh, &list, "", pattern_bits, n_sep); for ( i=0; i<n_sep; i++ ) { - free(pattern_bits[i]); + cffree(pattern_bits[i]); } - free(pattern_bits); + cffree(pattern_bits); *n_evs = list.n_events; return list.events; @@ -1795,7 +1795,7 @@ static int rec_expand_dims(struct ev_list *list, size_t len; len = strlen(path_ev); - dim_ev = malloc(len+16); + dim_ev = cfmalloc(len+16); if ( dim_ev == NULL ) return 1; if ( n_placeholder_dims == 1 ) { @@ -1815,7 +1815,7 @@ static int rec_expand_dims(struct ev_list *list, } - free(dim_ev); + cffree(dim_ev); return 0; } @@ -1953,8 +1953,8 @@ char **image_hdf5_expand_frames(const DataTemplate *dtempl, return NULL; } - size = malloc(dims*sizeof(hsize_t)); - placeholder_sizes = malloc(dims*sizeof(int)); + size = cfmalloc(dims*sizeof(hsize_t)); + placeholder_sizes = cfmalloc(dims*sizeof(int)); if ( (size == NULL) || (placeholder_sizes == NULL) ) { ERROR("Failed to allocate dimensions\n"); close_hdf5(fh); @@ -1973,7 +1973,7 @@ char **image_hdf5_expand_frames(const DataTemplate *dtempl, placeholder_sizes[n_placeholder_dims++] = size[j]; } } - free(size); + cffree(size); /* Path event ID ends with //, but expand_dims will * add a slash. So, remove one slash */ @@ -1990,10 +1990,10 @@ char **image_hdf5_expand_frames(const DataTemplate *dtempl, for ( j=0; j<n_evs_this_path; j++ ) { add_ev_to_list(&full_evs, evs_this_path[j]); - free(evs_this_path[j]); + cffree(evs_this_path[j]); } - free(evs_this_path); + cffree(evs_this_path); } else { @@ -2002,14 +2002,14 @@ char **image_hdf5_expand_frames(const DataTemplate *dtempl, } - free(placeholder_sizes); - free(path); - free(path_evs[i]); + cffree(placeholder_sizes); + cffree(path); + cffree(path_evs[i]); } close_hdf5(fh); - free(path_evs); + cffree(path_evs); *pn_frames = full_evs.n_events; return full_evs.events; } diff --git a/libcrystfel/src/image-msgpack.c b/libcrystfel/src/image-msgpack.c index 4ec55921..f305f9be 100644 --- a/libcrystfel/src/image-msgpack.c +++ b/libcrystfel/src/image-msgpack.c @@ -234,7 +234,7 @@ static char *terminate_str(const char *ptr, size_t len) char *str; if ( len < 1 ) return NULL; if ( len > 16*1024 ) return NULL; - str = malloc(len+1); + str = cfmalloc(len+1); if ( str == NULL ) return NULL; strncpy(str, ptr, len); str[len] = '\0'; @@ -301,7 +301,7 @@ int image_msgpack_read_header_to_cache(struct image *image, } image_cache_header_str(image, name, str); - free(str); + cffree(str); msgpack_unpacked_destroy(&unpacked); return 0; @@ -356,23 +356,23 @@ static int load_msgpack_data(struct panel_template *p, ERROR("Data 'type' isn't a string\n"); return 1; } - dtype = strndup(type_obj->via.str.ptr, type_obj->via.str.size); + dtype = cfstrndup(type_obj->via.str.ptr, type_obj->via.str.size); shape_obj = find_msgpack_kv(obj, "shape"); if ( shape_obj == NULL ) { ERROR("Data 'shape' not found\n"); - free(dtype); + cffree(dtype); return 1; } if ( shape_obj->type != MSGPACK_OBJECT_ARRAY ) { ERROR("Data 'shape' isn't an array\n"); - free(dtype); + cffree(dtype); return 1; } if ( shape_obj->via.array.size != 2 ) { ERROR("Data 'shape' has wrong number of dimensions (%i)\n", shape_obj->via.array.size); - free(dtype); + cffree(dtype); return 1; } data_size_ss = shape_obj->via.array.ptr[0].via.u64; @@ -393,12 +393,12 @@ static int load_msgpack_data(struct panel_template *p, data_obj = find_msgpack_kv(obj, "data"); if ( data_obj == NULL ) { ERROR("Data 'data' not found\n"); - free(dtype); + cffree(dtype); return 1; } if ( data_obj->type != MSGPACK_OBJECT_BIN ) { ERROR("Data 'data' isn't binary\n"); - free(dtype); + cffree(dtype); return 1; } @@ -434,7 +434,7 @@ static int load_msgpack_data(struct panel_template *p, ERROR("Unrecognised data type '%s'\n", dtype); } - free(dtype); + cffree(dtype); return 0; } diff --git a/libcrystfel/src/image-seedee.c b/libcrystfel/src/image-seedee.c index 2a4328ec..1b68aead 100644 --- a/libcrystfel/src/image-seedee.c +++ b/libcrystfel/src/image-seedee.c @@ -170,20 +170,20 @@ int image_seedee_read(struct image *image, data_block, data_block_size, &zero_copy, &array); profile_end("seedee-get-size"); - array.data = malloc(array.size); - array.shape = malloc(array.ndims*sizeof(int)); + array.data = cfmalloc(array.size); + array.shape = cfmalloc(array.ndims*sizeof(int)); if ( (array.data == NULL) || (array.shape == NULL) ) { cJSON_Delete(json); - free(array.data); - free(array.shape); + cffree(array.data); + cffree(array.shape); return 1; } if ( array.ndims != 2 ) { ERROR("Seedee data has unexpected number of dimensions " "(%i, expected 2)\n", array.ndims); - free(array.data); - free(array.shape); + cffree(array.data); + cffree(array.shape); return 1; } @@ -195,8 +195,8 @@ int image_seedee_read(struct image *image, cJSON_Delete(json); if ( r < 0 ) { ERROR("Seedee deserialiation failed.\n"); - free(array.data); - free(array.shape); + cffree(array.data); + cffree(array.shape); return 1; } @@ -208,15 +208,15 @@ int image_seedee_read(struct image *image, ERROR("Failed to load data for panel '%s'\n", dtempl->panels[i].name); profile_end("seedee-panel"); - free(array.data); - free(array.shape); + cffree(array.data); + cffree(array.shape); return 1; } } profile_end("seedee-panel"); - free(array.data); - free(array.shape); + cffree(array.data); + cffree(array.shape); return 0; } diff --git a/libcrystfel/src/image.c b/libcrystfel/src/image.c index 53ae796d..0789c6a3 100644 --- a/libcrystfel/src/image.c +++ b/libcrystfel/src/image.c @@ -158,7 +158,7 @@ void image_add_feature(ImageFeatureList *flist, double fs, double ss, if ( flist->n_features == flist->max_features ) { struct imagefeature *nf; int nmf = flist->max_features + 128; - nf = realloc(flist->features, nmf*sizeof(struct imagefeature)); + nf = cfrealloc(flist->features, nmf*sizeof(struct imagefeature)); if ( nf == NULL ) return; flist->features = nf; flist->max_features = nmf; @@ -178,7 +178,7 @@ ImageFeatureList *image_feature_list_new() { ImageFeatureList *flist; - flist = malloc(sizeof(ImageFeatureList)); + flist = cfmalloc(sizeof(ImageFeatureList)); flist->n_features = 0; flist->max_features = 0; @@ -207,9 +207,9 @@ ImageFeatureList *image_feature_list_copy(const ImageFeatureList *flist) n = image_feature_list_new(); if ( n == NULL ) return NULL; - n->features = malloc(flist->n_features*sizeof(struct imagefeature)); + n->features = cfmalloc(flist->n_features*sizeof(struct imagefeature)); if ( n->features == NULL ) { - free(n); + cffree(n); return NULL; } @@ -241,8 +241,8 @@ ImageFeatureList *sort_peaks(ImageFeatureList *flist) void image_feature_list_free(ImageFeatureList *flist) { if ( flist == NULL ) return; - free(flist->features); - free(flist); + cffree(flist->features); + cffree(flist); } @@ -323,7 +323,7 @@ void image_add_crystal(struct image *image, Crystal *cryst) int n; n = image->n_crystals; - crs = realloc(image->crystals, (n+1)*sizeof(Crystal *)); + crs = cfrealloc(image->crystals, (n+1)*sizeof(Crystal *)); if ( crs == NULL ) { ERROR("Failed to allocate memory for crystals.\n"); return; @@ -370,7 +370,7 @@ void free_all_crystals(struct image *image) cell_free(crystal_get_cell(cr)); crystal_free(image->crystals[i]); } - free(image->crystals); + cffree(image->crystals); image->n_crystals = 0; } @@ -397,10 +397,10 @@ void image_cache_header_int(struct image *image, } else { struct header_cache_entry *ce; - ce = malloc(sizeof(struct header_cache_entry)); + ce = cfmalloc(sizeof(struct header_cache_entry)); if ( ce != NULL ) { - ce->header_name = strdup(header_name); + ce->header_name = cfstrdup(header_name); ce->val_int = header_val; ce->type = HEADER_INT; image->header_cache[image->n_cached_headers++] = ce; @@ -420,10 +420,10 @@ void image_cache_header_float(struct image *image, } else { struct header_cache_entry *ce; - ce = malloc(sizeof(struct header_cache_entry)); + ce = cfmalloc(sizeof(struct header_cache_entry)); if ( ce != NULL ) { - ce->header_name = strdup(header_name); + ce->header_name = cfstrdup(header_name); ce->val_float = header_val; ce->type = HEADER_FLOAT; image->header_cache[image->n_cached_headers++] = ce; @@ -448,11 +448,11 @@ void image_cache_header_str(struct image *image, } else { struct header_cache_entry *ce; - ce = malloc(sizeof(struct header_cache_entry)); + ce = cfmalloc(sizeof(struct header_cache_entry)); if ( ce != NULL ) { - ce->header_name = strdup(header_name); - ce->val_str = strdup(header_val); + ce->header_name = cfstrdup(header_name); + ce->val_str = cfstrdup(header_val); ce->type = HEADER_STR; image->header_cache[image->n_cached_headers++] = ce; } else { @@ -612,7 +612,7 @@ struct _image_data_arrays ImageDataArrays *image_data_arrays_new() { - ImageDataArrays *ida = malloc(sizeof(struct _image_data_arrays)); + ImageDataArrays *ida = cfmalloc(sizeof(struct _image_data_arrays)); if ( ida == NULL ) return NULL; ida->dp = NULL; @@ -628,14 +628,14 @@ void image_data_arrays_free(ImageDataArrays *ida) int i; for ( i=0; i<ida->np; i++ ) { - if ( ida->dp != NULL ) free(ida->dp[i]); - if ( ida->bad != NULL ) free(ida->bad[i]); + if ( ida->dp != NULL ) cffree(ida->dp[i]); + if ( ida->bad != NULL ) cffree(ida->bad[i]); } - free(ida->dp); - free(ida->bad); + cffree(ida->dp); + cffree(ida->bad); - free(ida); + cffree(ida); } @@ -656,16 +656,16 @@ int image_create_dp_bad(struct image *image, /* Allocate new arrays */ - image->dp = malloc(dtempl->n_panels*sizeof(float *)); + image->dp = cfmalloc(dtempl->n_panels*sizeof(float *)); if ( image->dp == NULL ) { ERROR("Failed to allocate data array.\n"); return 1; } - image->bad = malloc(dtempl->n_panels*sizeof(int *)); + image->bad = cfmalloc(dtempl->n_panels*sizeof(int *)); if ( image->bad == NULL ) { ERROR("Failed to allocate bad pixel mask\n"); - free(image->dp); + cffree(image->dp); return 1; } @@ -679,17 +679,17 @@ int image_create_dp_bad(struct image *image, size_t nel = PANEL_WIDTH(&dtempl->panels[i]) * PANEL_HEIGHT(&dtempl->panels[i]); - image->dp[i] = malloc(nel*sizeof(float)); - image->bad[i] = malloc(nel*sizeof(int)); + image->dp[i] = cfmalloc(nel*sizeof(float)); + image->bad[i] = cfmalloc(nel*sizeof(int)); if ( (image->dp[i] == NULL)|| (image->bad[i] == NULL) ) { ERROR("Failed to allocate panel data arrays\n"); for ( i=0; i<dtempl->n_panels; i++ ) { - free(image->dp[i]); - free(image->bad[i]); + cffree(image->dp[i]); + cffree(image->bad[i]); } - free(image->dp); - free(image->bad); + cffree(image->dp); + cffree(image->bad); return 1; } @@ -1115,7 +1115,7 @@ static int create_satmap(struct image *image, if ( !any ) return 0; - image->sat = malloc(dtempl->n_panels * sizeof(float *)); + image->sat = cfmalloc(dtempl->n_panels * sizeof(float *)); if ( image->sat == NULL ) { ERROR("Failed to allocate saturation map\n"); return 1; @@ -1136,7 +1136,7 @@ static int create_satmap(struct image *image, p_w = p->orig_max_fs - p->orig_min_fs + 1; p_h = p->orig_max_ss - p->orig_min_ss + 1; - image->sat[i] = malloc(p_w*p_h*sizeof(float)); + image->sat[i] = cfmalloc(p_w*p_h*sizeof(float)); if ( image->sat[i] != NULL ) { long int j; @@ -1319,11 +1319,11 @@ struct image *image_read(const DataTemplate *dtempl, return NULL; } - image->filename = strdup(filename); + image->filename = cfstrdup(filename); if ( event != NULL ) { - image->ev = strdup(event); + image->ev = cfstrdup(event); } else { - image->ev = strdup("//"); /* Null event */ + image->ev = cfstrdup("//"); /* Null event */ } image->data_block = NULL; image->data_block_size = 0; @@ -1390,10 +1390,10 @@ void image_free(struct image *image) image_feature_list_free(image->features); free_all_crystals(image); spectrum_free(image->spectrum); - free(image->filename); - free(image->ev); - free(image->data_block); - free(image->meta_data); + cffree(image->filename); + cffree(image->ev); + cffree(image->data_block); + cffree(image->meta_data); if ( image->detgeom != NULL ) { np = image->detgeom->n_panels; @@ -1405,23 +1405,23 @@ void image_free(struct image *image) if ( image->ida == NULL ) { for ( i=0; i<np; i++ ) { - if ( image->dp != NULL ) free(image->dp[i]); - if ( image->sat != NULL ) free(image->sat[i]); - if ( image->bad != NULL ) free(image->bad[i]); + if ( image->dp != NULL ) cffree(image->dp[i]); + if ( image->sat != NULL ) cffree(image->sat[i]); + if ( image->bad != NULL ) cffree(image->bad[i]); } - free(image->dp); - free(image->sat); - free(image->bad); + cffree(image->dp); + cffree(image->sat); + cffree(image->bad); } /* else the arrays belong to the IDA structure */ for ( i=0; i<image->n_cached_headers; i++ ) { - free(image->header_cache[i]->header_name); - free(image->header_cache[i]); + cffree(image->header_cache[i]->header_name); + cffree(image->header_cache[i]); } - free(image); + cffree(image); } @@ -1429,7 +1429,7 @@ struct image *image_new() { struct image *image; - image = malloc(sizeof(struct image)); + image = cfmalloc(sizeof(struct image)); if ( image == NULL ) return NULL; image->dp = NULL; @@ -1536,11 +1536,11 @@ char **image_expand_frames(const DataTemplate *dtempl, } else { char **list; - list = malloc(sizeof(char *)); + list = cfmalloc(sizeof(char *)); if ( list == NULL ) return NULL; - list[0] = strdup("//"); + list[0] = cfstrdup("//"); if ( list[0] == NULL ) { - free(list); + cffree(list); return NULL; } *n_frames = 1; diff --git a/libcrystfel/src/index.c b/libcrystfel/src/index.c index db2058a5..4c35d2ca 100644 --- a/libcrystfel/src/index.c +++ b/libcrystfel/src/index.c @@ -121,7 +121,7 @@ char *base_indexer_str(IndexingMethod indm) { char *str; - str = malloc(256); + str = cfmalloc(256); if ( str == NULL ) { ERROR("Failed to allocate string.\n"); return NULL; @@ -270,11 +270,11 @@ static void *prepare_method(IndexingMethod *m, UnitCell *cell, if ( priv == NULL ) { ERROR("Failed to prepare indexing method %s\n", str); - free(str); + cffree(str); return NULL; } - free(str); + cffree(str); if ( in != *m ) { ERROR("Note: flags were altered to take into account " @@ -296,7 +296,7 @@ IndexingMethod *parse_indexing_methods(const char *method_list, n = assplode(method_list, ",", &method_strings, ASSPLODE_NONE); - methods = malloc(n * sizeof(IndexingMethod)); + methods = cfmalloc(n * sizeof(IndexingMethod)); if ( methods == NULL ) { ERROR("Failed to allocate indexing method list\n"); return NULL; @@ -316,12 +316,12 @@ IndexingMethod *parse_indexing_methods(const char *method_list, ERROR("To disable indexing retry ('noretry'), use --no-retry.\n"); ERROR("To enable multi-lattice indexing by 'delete and retry', use --multi\n"); ERROR("------------------\n"); - free(methods); + cffree(methods); return NULL; } - free(method_strings[i]); + cffree(method_strings[i]); } - free(method_strings); + cffree(method_strings); *pn = n; return methods; @@ -393,13 +393,13 @@ IndexingPrivate *setup_indexing(const char *method_list, } - ipriv = malloc(sizeof(struct _indexingprivate)); + ipriv = cfmalloc(sizeof(struct _indexingprivate)); if ( ipriv == NULL ) { ERROR("Failed to allocate indexing data\n"); return NULL; } - ipriv->engine_private = malloc((n+1) * sizeof(void *)); + ipriv->engine_private = cfmalloc((n+1) * sizeof(void *)); for ( i=0; i<n; i++ ) { @@ -416,14 +416,14 @@ IndexingPrivate *setup_indexing(const char *method_list, asdf_opts); if ( ipriv->engine_private[i] == NULL ) { - free(ipriv->engine_private); + cffree(ipriv->engine_private); return NULL; } for ( j=0; j<i; j++ ) { if ( methods[i] == methods[j] ) { ERROR("Duplicate indexing method.\n"); - free(ipriv->engine_private); + cffree(ipriv->engine_private); return NULL; } } @@ -449,8 +449,8 @@ IndexingPrivate *setup_indexing(const char *method_list, char *str = indexer_str(methods[i]); char *tmp = friendly_indexer_name(methods[i]); STATUS(" %2i: %-25s (%s)\n", i, str, tmp); - free(str); - free(tmp); + cffree(str); + cffree(tmp); } show_indexing_flags(flags); @@ -523,10 +523,10 @@ void cleanup_indexing(IndexingPrivate *ipriv) } - free(ipriv->methods); - free(ipriv->engine_private); + cffree(ipriv->methods); + cffree(ipriv->engine_private); cell_free(ipriv->target_cell); - free(ipriv); + cffree(ipriv); } @@ -1194,10 +1194,10 @@ IndexingMethod get_indm_from_string_2(const char *str, int *err) return INDEXING_ERROR; } - free(bits[i]); + cffree(bits[i]); } - free(bits); + cffree(bits); if ( !have_method ) return warn_method(str); @@ -1229,7 +1229,7 @@ char *detect_indexing_methods(UnitCell *cell) { char *methods; - methods = malloc(1024); + methods = cfmalloc(1024); if ( methods == NULL ) return NULL; methods[0] = '\0'; @@ -1244,7 +1244,7 @@ char *detect_indexing_methods(UnitCell *cell) //do_probe(pinkIndexer_probe, cell, methods); if ( strlen(methods) == 0 ) { - free(methods); + cffree(methods); return NULL; } diff --git a/libcrystfel/src/indexers/asdf.c b/libcrystfel/src/indexers/asdf.c index 2222144b..919e570f 100644 --- a/libcrystfel/src/indexers/asdf.c +++ b/libcrystfel/src/indexers/asdf.c @@ -132,7 +132,7 @@ struct tvector tvector_new(int n) t.t = gsl_vector_alloc(3); t.n = 0; - t.fits = malloc(sizeof(int) * n); + t.fits = cfmalloc(sizeof(int) * n); return t; } @@ -141,7 +141,7 @@ struct tvector tvector_new(int n) static int tvector_free(struct tvector t) { gsl_vector_free(t.t); - free(t.fits); + cffree(t.fits); return 1; } @@ -155,12 +155,12 @@ static int asdf_cell_free(struct asdf_cell *c) gsl_vector_free(c->reciprocal[i]); } - free(c->reflections); + cffree(c->reflections); for ( i = 0; i < c->N_refls; i++ ) { - free(c->indices[i]); + cffree(c->indices[i]); } - free(c->indices); - free(c); + cffree(c->indices); + cffree(c); return 1; } @@ -169,7 +169,7 @@ static int asdf_cell_free(struct asdf_cell *c) static struct asdf_cell *asdf_cell_new(int n) { struct asdf_cell *c; - c = malloc(sizeof(struct asdf_cell)); + c = cfmalloc(sizeof(struct asdf_cell)); int i; for ( i = 0; i < 3; i++ ) { @@ -178,20 +178,20 @@ static struct asdf_cell *asdf_cell_new(int n) } c->N_refls = n; - c->reflections = malloc(sizeof(int) * n); + c->reflections = cfmalloc(sizeof(int) * n); if (c->reflections == NULL) return NULL; - c->indices = malloc(sizeof(double *) * n); + c->indices = cfmalloc(sizeof(double *) * n); if (c->indices == NULL) { - free(c->reflections); + cffree(c->reflections); return NULL; } for ( i = 0; i < n; i++ ) { - c->indices[i] = malloc(sizeof(double) * 3); + c->indices[i] = cfmalloc(sizeof(double) * 3); if (c->indices[i] == NULL) { - free(c->reflections); - free(c->indices); + cffree(c->reflections); + cffree(c->indices); return NULL; } } @@ -224,7 +224,7 @@ static int asdf_cell_memcpy(struct asdf_cell *dest, struct asdf_cell *src) memcpy(dest->indices[i], src->indices[i], sizeof(double) * 3); } for ( i=n; i<dest->N_refls; i++ ) { - free(dest->indices[i]); + cffree(dest->indices[i]); } dest->N_refls = n; @@ -928,7 +928,7 @@ static int **generate_triplets(int N_reflections, int N_triplets_max, int *N) } *N = N_triplets; - int **triplets = malloc(N_triplets * sizeof(int *)); + int **triplets = cfmalloc(N_triplets * sizeof(int *)); if ( triplets == NULL ) { ERROR("Failed to allocate triplets in generate_triplets!\n"); @@ -940,7 +940,7 @@ static int **generate_triplets(int N_reflections, int N_triplets_max, int *N) // Reservoir sampling: for ( i = 0; i < N_triplets_tot; i++ ) { if ( n < N_triplets ) { - triplets[n] = (int *)malloc(3 * sizeof(int)); + triplets[n] = (int *)cfmalloc(3 * sizeof(int)); if (triplets[n] == NULL) { ERROR("Failed to allocate triplet in generate_triplets!\n"); return NULL; @@ -957,10 +957,10 @@ static int **generate_triplets(int N_reflections, int N_triplets_max, int *N) } } else { // Random selection from the whole set: - int *tidx = (int *)malloc(N_triplets * sizeof(int)); + int *tidx = (int *)cfmalloc(N_triplets * sizeof(int)); if ( tidx == NULL ) { ERROR("Failed to allocate tidx in generate_triplets_2!\n"); - free(triplets); + cffree(triplets); return NULL; } while ( n < N_triplets ) { @@ -973,7 +973,7 @@ static int **generate_triplets(int N_reflections, int N_triplets_max, int *N) } } tidx[n] = ri; - triplets[n] = (int *)malloc(3 * sizeof(int)); + triplets[n] = (int *)cfmalloc(3 * sizeof(int)); if ( triplets[n] == NULL ) { ERROR("Failed to allocate triplet in generate_triplets!\n"); return NULL; @@ -981,7 +981,7 @@ static int **generate_triplets(int N_reflections, int N_triplets_max, int *N) get_triplet_by_index(ri, N_reflections, triplets[n]); n += 1; } - free(tidx); + cffree(tidx); } return triplets; } @@ -1002,7 +1002,7 @@ static int index_refls(gsl_vector **reflections, int N_reflections, int N_refl_m gsl_vector **refl_sample; if ( N_reflections > N_refl_max ) { - refl_sample = (gsl_vector **)malloc(N_refl_max * sizeof(gsl_vector *)); + refl_sample = (gsl_vector **)cfmalloc(N_refl_max * sizeof(gsl_vector *)); n = 0; for ( i = 0; i < N_reflections; i++ ) { if (i < N_refl_max) { @@ -1029,18 +1029,18 @@ static int index_refls(gsl_vector **reflections, int N_reflections, int N_refl_m double projections[N_refl_max]; double ds; - int *fits = malloc(N_refl_max * sizeof(int)); + int *fits = cfmalloc(N_refl_max * sizeof(int)); if ( fits == NULL ) { ERROR("Failed to allocate fits in index_refls!\n"); - if ( N_reflections > N_refl_max ) free(refl_sample); + if ( N_reflections > N_refl_max ) cffree(refl_sample); return 0; } - struct tvector *tvectors = malloc(N_triplets * sizeof(struct tvector)); + struct tvector *tvectors = cfmalloc(N_triplets * sizeof(struct tvector)); if ( tvectors == NULL ) { ERROR("Failed to allocate tvectors in index_refls!\n"); - if ( N_reflections > N_refl_max ) free(refl_sample); - free(fits); + if ( N_reflections > N_refl_max ) cffree(refl_sample); + cffree(fits); return 0; } @@ -1113,20 +1113,20 @@ static int index_refls(gsl_vector **reflections, int N_reflections, int N_refl_m } } profile_end("asdf-search"); - free(fits); + cffree(fits); for ( i = 0; i < N_tvectors; i++ ) { tvector_free(tvectors[i]); } - free(tvectors); + cffree(tvectors); for ( i = 0; i < N_triplets; i++ ) { - free(triplets[i]); + cffree(triplets[i]); } - free(triplets); + cffree(triplets); gsl_vector_free(normal); - if ( N_reflections > N_refl_max ) free(refl_sample); + if ( N_reflections > N_refl_max ) cffree(refl_sample); if ( c->n ) return 1; @@ -1262,7 +1262,7 @@ void *asdf_prepare(IndexingMethod *indm, UnitCell *cell, struct asdf_options *as /* Flags that asdf knows about */ *indm &= INDEXING_METHOD_MASK | INDEXING_USE_CELL_PARAMETERS; - dp = malloc(sizeof(struct asdf_private)); + dp = cfmalloc(sizeof(struct asdf_private)); if ( dp == NULL ) return NULL; dp->template = cell; @@ -1279,7 +1279,7 @@ void asdf_cleanup(void *pp) struct asdf_private *p; p = (struct asdf_private *)pp; fftw_vars_free(p->fftw); - free(p); + cffree(p); } @@ -1332,7 +1332,7 @@ int asdf_default_options(struct asdf_options **opts_ptr) { struct asdf_options *opts; - opts = malloc(sizeof(struct asdf_options)); + opts = cfmalloc(sizeof(struct asdf_options)); if ( opts == NULL ) return ENOMEM; opts->fast_execution = 0; diff --git a/libcrystfel/src/indexers/dirax.c b/libcrystfel/src/indexers/dirax.c index 9c427879..88384e11 100644 --- a/libcrystfel/src/indexers/dirax.c +++ b/libcrystfel/src/indexers/dirax.c @@ -118,13 +118,13 @@ static void dirax_parseline(const char *line, struct image *image, #if DIRAX_VERBOSE char *copy; - copy = strdup(line); + copy = cfstrdup(line); for ( i=0; i<strlen(copy); i++ ) { if ( copy[i] == '\r' ) copy[i]='r'; if ( copy[i] == '\n' ) copy[i]='\0'; } STATUS("DirAx: %s\n", copy); - free(copy); + cffree(copy); #endif if ( strstr(line, "reflections from file") ) { @@ -250,13 +250,13 @@ static void dirax_sendline(const char *line, struct dirax_data *dirax) char *copy; int i; - copy = strdup(line); + copy = cfstrdup(line); for ( i=0; i<strlen(copy); i++ ) { if ( copy[i] == '\r' ) copy[i]='\0'; if ( copy[i] == '\n' ) copy[i]='\0'; } STATUS("To DirAx: '%s'\n", copy); - free(copy); + cffree(copy); #endif if ( write(dirax->pty, line, strlen(line)) == -1 ) { @@ -399,7 +399,7 @@ static int dirax_readable(struct image *image, struct dirax_data *dirax) case DIRAX_INPUT_LINE : /* Make buffer a bit too big to keep Valgrind * quiet about alignment errors */ - block_buffer = malloc(i+4); + block_buffer = cfmalloc(i+4); memcpy(block_buffer, dirax->rbuffer, i); block_buffer[i] = '\0'; @@ -408,7 +408,7 @@ static int dirax_readable(struct image *image, struct dirax_data *dirax) } dirax_parseline(block_buffer, image, dirax); - free(block_buffer); + cffree(block_buffer); endbit_length = i+2; break; @@ -441,8 +441,7 @@ static int dirax_readable(struct image *image, struct dirax_data *dirax) - endbit_length; new_rbuflen = dirax->rbuflen - endbit_length; if ( new_rbuflen == 0 ) new_rbuflen = 256; - dirax->rbuffer = realloc(dirax->rbuffer, - new_rbuflen); + dirax->rbuffer = cfrealloc(dirax->rbuffer, new_rbuflen); dirax->rbuflen = new_rbuflen; } else { @@ -450,8 +449,8 @@ static int dirax_readable(struct image *image, struct dirax_data *dirax) if ( dirax->rbufpos == dirax->rbuflen ) { /* More buffer space is needed */ - dirax->rbuffer = realloc(dirax->rbuffer, - dirax->rbuflen + 256); + dirax->rbuffer = cfrealloc(dirax->rbuffer, + dirax->rbuflen + 256); dirax->rbuflen = dirax->rbuflen + 256; /* The new space gets used at the next * read, shortly... */ @@ -511,7 +510,7 @@ int run_dirax(struct image *image, void *ipriv) write_drx(image); - dirax = malloc(sizeof(struct dirax_data)); + dirax = cfmalloc(sizeof(struct dirax_data)); if ( dirax == NULL ) { ERROR("Couldn't allocate memory for DirAx data.\n"); return 0; @@ -538,7 +537,7 @@ int run_dirax(struct image *image, void *ipriv) } - dirax->rbuffer = malloc(256); + dirax->rbuffer = cfmalloc(256); dirax->rbuflen = 256; dirax->rbufpos = 0; @@ -595,7 +594,7 @@ int run_dirax(struct image *image, void *ipriv) } while ( !rval && !dirax->success ); close(dirax->pty); - free(dirax->rbuffer); + cffree(dirax->rbuffer); waitpid(dirax->pid, &status, 0); if ( dirax->finished_ok == 0 ) { @@ -603,7 +602,7 @@ int run_dirax(struct image *image, void *ipriv) } rval = dirax->success; - free(dirax); + cffree(dirax); return rval; } @@ -621,7 +620,7 @@ void *dirax_prepare(IndexingMethod *indm, UnitCell *cell) /* Flags that DirAx knows about */ *indm &= INDEXING_METHOD_MASK; - dp = malloc(sizeof(struct dirax_private)); + dp = cfmalloc(sizeof(struct dirax_private)); if ( dp == NULL ) return NULL; dp->template = cell; @@ -635,7 +634,7 @@ void dirax_cleanup(void *pp) { struct dirax_private *p; p = (struct dirax_private *)pp; - free(p); + cffree(p); } diff --git a/libcrystfel/src/indexers/felix.c b/libcrystfel/src/indexers/felix.c index db7da8c4..d6632e42 100644 --- a/libcrystfel/src/indexers/felix.c +++ b/libcrystfel/src/indexers/felix.c @@ -277,7 +277,7 @@ static int felix_readable(struct image *image, struct felix_data *gs) unsigned int endbit_length; char *block_buffer = NULL; - block_buffer = malloc(i+1); + block_buffer = cfmalloc(i+1); memcpy(block_buffer, gs->rbuffer, i); block_buffer[i] = '\0'; @@ -286,7 +286,7 @@ static int felix_readable(struct image *image, struct felix_data *gs) } gs_parseline(block_buffer, image, gs); - free(block_buffer); + cffree(block_buffer); endbit_length = i+2; /* Now the block's been parsed, it should be @@ -299,7 +299,7 @@ static int felix_readable(struct image *image, struct felix_data *gs) gs->rbufpos = gs->rbufpos - endbit_length; new_rbuflen = gs->rbuflen - endbit_length; if ( new_rbuflen == 0 ) new_rbuflen = 256; - gs->rbuffer = realloc(gs->rbuffer, new_rbuflen); + gs->rbuffer = cfrealloc(gs->rbuffer, new_rbuflen); gs->rbuflen = new_rbuflen; } else { @@ -307,8 +307,8 @@ static int felix_readable(struct image *image, struct felix_data *gs) if ( gs->rbufpos == gs->rbuflen ) { /* More buffer space is needed */ - gs->rbuffer = realloc(gs->rbuffer, - gs->rbuflen + 256); + gs->rbuffer = cfrealloc(gs->rbuffer, + gs->rbuflen + 256); gs->rbuflen = gs->rbuflen + 256; /* The new space gets used at the next * read, shortly... */ @@ -374,7 +374,7 @@ static char *write_ini(struct image *image, struct felix_private *gp) char gveFilename[1024]; char logFilename[1024]; - filename = malloc(1024); + filename = cfmalloc(1024); if ( filename == NULL ) return NULL; snprintf(filename, 1023, "xfel.ini"); @@ -384,7 +384,7 @@ static char *write_ini(struct image *image, struct felix_private *gp) fh = fopen(filename, "w"); if ( !fh ) { ERROR("Couldn't open temporary file '%s'\n", filename); - free(filename); + cffree(filename); return NULL; } @@ -413,7 +413,7 @@ static char *write_ini(struct image *image, struct felix_private *gp) fprintf(fh, "orispace octa\n"); } else{ ERROR("No felix supported orispace specified.\n"); - free(filename); + cffree(filename); filename = NULL; } @@ -450,7 +450,7 @@ int felix_index(struct image *image, IndexingPrivate *ipriv) return 0; } - felix = malloc(sizeof(struct felix_data)); + felix = cfmalloc(sizeof(struct felix_data)); if ( felix == NULL ) { ERROR("Couldn't allocate memory for Felix data.\n"); return 0; @@ -483,9 +483,9 @@ int felix_index(struct image *image, IndexingPrivate *ipriv) } - free(ini_filename); + cffree(ini_filename); - felix->rbuffer = malloc(256); + felix->rbuffer = cfmalloc(256); felix->rbuflen = 256; felix->rbufpos = 0; @@ -534,18 +534,18 @@ int felix_index(struct image *image, IndexingPrivate *ipriv) } while ( !rval ); close(felix->pty); - free(felix->rbuffer); + cffree(felix->rbuffer); waitpid(felix->pid, &status, 0); if ( status != 0 ) { ERROR("Felix either timed out, or is not working properly.\n"); - free(felix); + cffree(felix); return 0; } rval = read_felix(gp, image, gff_filename); - free(felix); + cffree(felix); return rval; } @@ -625,7 +625,7 @@ void *felix_prepare(IndexingMethod *indm, UnitCell *cell, return NULL; } - gp = calloc(1, sizeof(*gp)); + gp = cfcalloc(1, sizeof(*gp)); if ( gp == NULL ) return NULL; /* Flags that Felix knows about */ @@ -640,7 +640,7 @@ void *felix_prepare(IndexingMethod *indm, UnitCell *cell, if ( gp->spacegroup == 0 ) { ERROR("Couldn't determine representative space group for your cell.\n"); ERROR("Try again with a more conventional cell.\n"); - free(gp); + cffree(gp); return NULL; } @@ -710,8 +710,8 @@ void felix_cleanup(IndexingPrivate *pp) struct felix_private *p; p = (struct felix_private *) pp; - free(p->readhkl_file); - free(p); + cffree(p->readhkl_file); + cffree(p); } @@ -812,7 +812,7 @@ int felix_default_options(struct felix_options **opts_ptr) { struct felix_options *opts; - opts = malloc(sizeof(struct felix_options)); + opts = cfmalloc(sizeof(struct felix_options)); if ( opts == NULL ) return ENOMEM; opts->ttmin = -1.0; diff --git a/libcrystfel/src/indexers/fromfile.c b/libcrystfel/src/indexers/fromfile.c index 1716dd66..c7f1d1ba 100644 --- a/libcrystfel/src/indexers/fromfile.c +++ b/libcrystfel/src/indexers/fromfile.c @@ -101,7 +101,7 @@ struct fromfile_entry *add_unique(struct fromfile_entry **phead, struct fromfile_entry *item; - item = malloc(sizeof(struct fromfile_entry)); + item = cfmalloc(sizeof(struct fromfile_entry)); if ( item == NULL ) return NULL; item->n_crystals = 0; @@ -197,12 +197,12 @@ void *fromfile_prepare(IndexingMethod *indm, struct fromfile_options *opts) if ( opts->filename[0] == '/' ) { fh = fopen(opts->filename, "r"); } else { - char *prefixed_fn = malloc(4+strlen(opts->filename)); + char *prefixed_fn = cfmalloc(4+strlen(opts->filename)); if ( prefixed_fn == NULL ) return NULL; strcpy(prefixed_fn, "../"); strcat(prefixed_fn, opts->filename); fh = fopen(prefixed_fn, "r"); - free(prefixed_fn); + cffree(prefixed_fn); } if ( fh == NULL ) { @@ -210,7 +210,7 @@ void *fromfile_prepare(IndexingMethod *indm, struct fromfile_options *opts) return NULL; } - dp = malloc(sizeof(struct fromfile_private)); + dp = cfmalloc(sizeof(struct fromfile_private)); if ( dp == NULL ) { fclose(fh); return NULL; @@ -305,8 +305,8 @@ void *fromfile_prepare(IndexingMethod *indm, struct fromfile_options *opts) } - for ( i=0; i<n; i++ ) free(bits[i]); - free(bits); + for ( i=0; i<n; i++ ) cffree(bits[i]); + cffree(bits); } while ( 1 ); @@ -360,7 +360,7 @@ void fromfile_cleanup(void *mpriv) } } - free(dp); + cffree(dp); } @@ -376,7 +376,7 @@ static void fromfile_show_help() int fromfile_default_options(struct fromfile_options **opts_ptr) { struct fromfile_options *opts; - opts = malloc(sizeof(struct fromfile_options)); + opts = cfmalloc(sizeof(struct fromfile_options)); if ( opts == NULL ) return ENOMEM; opts->filename = NULL; *opts_ptr = opts; @@ -402,7 +402,7 @@ static error_t fromfile_parse_arg(int key, char *arg, return EINVAL; case 2 : - (*opts_ptr)->filename = strdup(arg); + (*opts_ptr)->filename = cfstrdup(arg); break; default : diff --git a/libcrystfel/src/indexers/mosflm.c b/libcrystfel/src/indexers/mosflm.c index 1bd53119..1cec0a35 100644 --- a/libcrystfel/src/indexers/mosflm.c +++ b/libcrystfel/src/indexers/mosflm.c @@ -162,13 +162,13 @@ static void mosflm_parseline(const char *line, struct image *image, char *copy; int i; - copy = strdup(line); + copy = cfstrdup(line); for ( i=0; i<strlen(copy); i++ ) { if ( copy[i] == '\r' ) copy[i]='r'; if ( copy[i] == '\n' ) copy[i]='\0'; } STATUS("MOSFLM: %s\n", copy); - free(copy); + cffree(copy); } } @@ -366,13 +366,13 @@ static void write_img(struct image *image, const char *filename) FILE *fh; unsigned short int *intimage; - intimage = malloc(sizeof(unsigned short int)); + intimage = cfmalloc(sizeof(unsigned short int)); intimage[0] = 1; fh = fopen(filename, "w"); if ( !fh ) { ERROR("Couldn't open temporary file '%s'\n", filename); - free(intimage); + cffree(intimage); return; } @@ -389,7 +389,7 @@ static void write_img(struct image *image, const char *filename) while ( ftell(fh) < 512 ) fprintf(fh," "); fwrite(intimage, sizeof(unsigned short int), 1, fh); - free(intimage); + cffree(intimage); fclose(fh); } @@ -400,13 +400,13 @@ static void mosflm_sendline(const char *line, struct mosflm_data *mosflm) char *copy; int i; - copy = strdup(line); + copy = cfstrdup(line); for ( i=0; i<strlen(copy); i++ ) { if ( copy[i] == '\r' ) copy[i]='\0'; if ( copy[i] == '\n' ) copy[i]='\0'; } STATUS("To MOSFLM: '%s'\n", copy); - free(copy); + cffree(copy); #endif if ( write(mosflm->pty, line, strlen(line)) == -1 ) { @@ -469,7 +469,7 @@ static char *mosflm_spacegroup_for_lattice(UnitCell *cell) } assert(g != NULL); - result = malloc(32); + result = cfmalloc(32); if ( result == NULL ) return NULL; snprintf(result, 31, "%c%s", centering, g); @@ -512,7 +512,7 @@ static void mosflm_send_next(struct image *image, struct mosflm_data *mosflm) symm = mosflm_spacegroup_for_lattice(mosflm->mp->template); snprintf(tmp, 255, "SYMM %s\n", symm); //STATUS("Asking MOSFLM for '%s'\n", symm); - free(symm); + cffree(symm); mosflm_sendline(tmp, mosflm); } else { @@ -629,7 +629,7 @@ static int mosflm_readable(struct image *image, struct mosflm_data *mosflm) switch ( type ) { case MOSFLM_INPUT_LINE : - block_buffer = malloc(i+1); + block_buffer = cfmalloc(i+1); memcpy(block_buffer, mosflm->rbuffer, i); block_buffer[i] = '\0'; @@ -638,7 +638,7 @@ static int mosflm_readable(struct image *image, struct mosflm_data *mosflm) } mosflm_parseline(block_buffer, image, mosflm); - free(block_buffer); + cffree(block_buffer); endbit_length = i+2; break; @@ -667,8 +667,8 @@ static int mosflm_readable(struct image *image, struct mosflm_data *mosflm) - endbit_length; new_rbuflen = mosflm->rbuflen - endbit_length; if ( new_rbuflen == 0 ) new_rbuflen = 256; - mosflm->rbuffer = realloc(mosflm->rbuffer, - new_rbuflen); + mosflm->rbuffer = cfrealloc(mosflm->rbuffer, + new_rbuflen); mosflm->rbuflen = new_rbuflen; } else { @@ -676,9 +676,8 @@ static int mosflm_readable(struct image *image, struct mosflm_data *mosflm) if ( mosflm->rbufpos==mosflm->rbuflen ) { /* More buffer space is needed */ - mosflm->rbuffer = realloc( - mosflm->rbuffer, - mosflm->rbuflen + 256); + mosflm->rbuffer = cfrealloc(mosflm->rbuffer, + mosflm->rbuflen + 256); mosflm->rbuflen = mosflm->rbuflen + 256; /* The new space gets used at the next * read, shortly... */ @@ -701,7 +700,7 @@ int run_mosflm(struct image *image, void *ipriv) int status; int rval; - mosflm = malloc(sizeof(struct mosflm_data)); + mosflm = cfmalloc(sizeof(struct mosflm_data)); if ( mosflm == NULL ) { ERROR("Couldn't allocate memory for MOSFLM data.\n"); return 0; @@ -720,7 +719,7 @@ int run_mosflm(struct image *image, void *ipriv) if ( mosflm->pid == -1 ) { ERROR("Failed to fork for MOSFLM: %s\n", strerror(errno)); - free(mosflm); + cffree(mosflm); return 0; } if ( mosflm->pid == 0 ) { @@ -741,7 +740,7 @@ int run_mosflm(struct image *image, void *ipriv) } - mosflm->rbuffer = malloc(256); + mosflm->rbuffer = cfmalloc(256); mosflm->rbuflen = 256; mosflm->rbufpos = 0; @@ -796,7 +795,7 @@ int run_mosflm(struct image *image, void *ipriv) } while ( !rval ); close(mosflm->pty); - free(mosflm->rbuffer); + cffree(mosflm->rbuffer); waitpid(mosflm->pid, &status, 0); if ( mosflm->finished_ok == 0 ) { @@ -807,7 +806,7 @@ int run_mosflm(struct image *image, void *ipriv) } rval = mosflm->success; - free(mosflm); + cffree(mosflm); return rval; } @@ -835,7 +834,7 @@ void *mosflm_prepare(IndexingMethod *indm, UnitCell *cell) "monoclinic C cell choice.\n"); } - mp = malloc(sizeof(struct mosflm_private)); + mp = cfmalloc(sizeof(struct mosflm_private)); if ( mp == NULL ) return NULL; mp->template = cell; @@ -849,7 +848,7 @@ void mosflm_cleanup(void *pp) { struct mosflm_private *p; p = (struct mosflm_private *)pp; - free(p); + cffree(p); } diff --git a/libcrystfel/src/indexers/pinkindexer.c b/libcrystfel/src/indexers/pinkindexer.c index 929c209b..180246c2 100644 --- a/libcrystfel/src/indexers/pinkindexer.c +++ b/libcrystfel/src/indexers/pinkindexer.c @@ -83,7 +83,7 @@ int run_pinkIndexer(struct image *image, void *ipriv, int n_threads) } reciprocalPeaks_1_per_A.peakCount = 0; - intensities = malloc(npk*sizeof(float)); + intensities = cfmalloc(npk*sizeof(float)); allocReciprocalPeaks(&reciprocalPeaks_1_per_A); if ( intensities == NULL ) return 0; @@ -116,7 +116,7 @@ int run_pinkIndexer(struct image *image, void *ipriv, int n_threads) pinkIndexer_private_data->maxRefinementDisbalance, n_threads); - free(intensities); + cffree(intensities); freeReciprocalPeaks(reciprocalPeaks_1_per_A); if ( matchedPeaksCount == -1 ) { @@ -205,7 +205,7 @@ void *pinkIndexer_prepare(IndexingMethod *indm, return NULL; } - struct pinkIndexer_private_data* pinkIndexer_private_data = malloc(sizeof(struct pinkIndexer_private_data)); + struct pinkIndexer_private_data* pinkIndexer_private_data = cfmalloc(sizeof(struct pinkIndexer_private_data)); pinkIndexer_private_data->indm = *indm; pinkIndexer_private_data->cellTemplate = cell; pinkIndexer_private_data->maxRefinementDisbalance = pinkIndexer_opts->maxRefinementDisbalance; @@ -424,7 +424,7 @@ int pinkIndexer_default_options(struct pinkindexer_options **opts_ptr) { struct pinkindexer_options *opts; - opts = malloc(sizeof(struct pinkindexer_options)); + opts = cfmalloc(sizeof(struct pinkindexer_options)); if ( opts == NULL ) return ENOMEM; opts->considered_peaks_count = 4; diff --git a/libcrystfel/src/indexers/taketwo.c b/libcrystfel/src/indexers/taketwo.c index 0b652b9f..c87d6b3d 100644 --- a/libcrystfel/src/indexers/taketwo.c +++ b/libcrystfel/src/indexers/taketwo.c @@ -524,7 +524,7 @@ static double matrix_trace(gsl_matrix *a) static char *add_unique_axis(const char *inp, char ua) { - char *pg = malloc(64); + char *pg = cfmalloc(64); if ( pg == NULL ) return NULL; snprintf(pg, 63, "%s_ua%c", inp, ua); return pg; @@ -584,7 +584,7 @@ static char *get_chiral_holohedry(UnitCell *cell) if ( add_ua ) { return add_unique_axis(pg, cell_get_unique_axis(cell)); } else { - return strdup(pg); + return cfstrdup(pg); } } @@ -595,7 +595,7 @@ static SymOpList *sym_ops_for_cell(UnitCell *cell) char *pg = get_chiral_holohedry(cell); rawList = get_pointgroup(pg); - free(pg); + cffree(pg); return rawList; } @@ -845,7 +845,7 @@ static int obs_vecs_match_angles(int her, int his, new_size *= sizeof(struct Seed); /* Reallocate the array to fit in another match */ - struct Seed *tmp_seeds = realloc(*seeds, new_size); + struct Seed *tmp_seeds = cfrealloc(*seeds, new_size); if ( tmp_seeds == NULL ) { apologise(); @@ -878,8 +878,8 @@ static signed int finish_solution(gsl_matrix *rot, struct SpotVec *obs_vecs, gsl_matrix *sub = gsl_matrix_calloc(3, 3); gsl_matrix *mul = gsl_matrix_calloc(3, 3); - gsl_matrix **rotations = malloc(sizeof(*rotations)* pow(member_num, 2) - - member_num); + gsl_matrix **rotations = cfmalloc(sizeof(*rotations)* pow(member_num, 2) + - member_num); int i, j, count; @@ -929,7 +929,7 @@ static signed int finish_solution(gsl_matrix *rot, struct SpotVec *obs_vecs, gsl_matrix_free(rotations[i]); } - free(rotations); + cffree(rotations); gsl_matrix_free(sub); gsl_matrix_free(mul); @@ -1011,7 +1011,7 @@ static int weed_duplicate_matches(struct Seed **seeds, } } - free(old_mats); + cffree(old_mats); return 1; } @@ -1310,8 +1310,8 @@ static unsigned int grow_network(gsl_matrix *rot, int obs_idx1, int obs_idx2, } /* indices of members of the self-consistent network of vectors */ - obs_members = malloc((cell->member_thresh+3)*sizeof(int)); - match_members = malloc((cell->member_thresh+3)*sizeof(int)); + obs_members = cfmalloc((cell->member_thresh+3)*sizeof(int)); + match_members = cfmalloc((cell->member_thresh+3)*sizeof(int)); if ( (obs_members == NULL) || (match_members == NULL) ) { apologise(); return 0; @@ -1334,8 +1334,8 @@ static unsigned int grow_network(gsl_matrix *rot, int obs_idx1, int obs_idx2, while ( 1 ) { if (start > obs_vec_count) { - free(obs_members); - free(match_members); + cffree(obs_members); + cffree(match_members); return 0; } @@ -1347,8 +1347,8 @@ static unsigned int grow_network(gsl_matrix *rot, int obs_idx1, int obs_idx2, &match_found, cell); if ( member_num < 2 ) { - free(obs_members); - free(match_members); + cffree(obs_members); + cffree(match_members); return 0; } @@ -1383,8 +1383,8 @@ static unsigned int grow_network(gsl_matrix *rot, int obs_idx1, int obs_idx2, finish_solution(rot, obs_vecs, obs_members, match_members, member_num, cell); - free(obs_members); - free(match_members); + cffree(obs_members); + cffree(match_members); return ( member_num ); } @@ -1519,7 +1519,7 @@ static int find_seeds(struct TakeTwoCell *cell, struct taketwo_private *tp) size_t new_size = cell->seed_count + seed_num; new_size *= sizeof(struct Seed); - struct Seed *tmp = realloc(cell->seeds, new_size); + struct Seed *tmp = cfrealloc(cell->seeds, new_size); if (tmp == NULL) { apologise(); @@ -1539,7 +1539,7 @@ static int find_seeds(struct TakeTwoCell *cell, struct taketwo_private *tp) cell->seed_count++; } - free(seeds); + cffree(seeds); } } @@ -1590,12 +1590,12 @@ static unsigned int start_seeds(gsl_matrix **rotation, struct TakeTwoCell *cell) } if (member_num >= NETWORK_MEMBER_THRESHOLD) { - free(seeds); + cffree(seeds); return max_members; } } - free(seeds); + cffree(seeds); return max_members; } @@ -1652,7 +1652,7 @@ static int generate_rotation_sym_ops(struct TakeTwoCell *ttCell) int i, j, k; int numOps = num_equivs(rawList, NULL); - ttCell->rotSymOps = malloc(numOps * sizeof(gsl_matrix *)); + ttCell->rotSymOps = cfmalloc(numOps * sizeof(gsl_matrix *)); ttCell->numOps = numOps; if (ttCell->rotSymOps == NULL) { @@ -1764,13 +1764,13 @@ static int match_obs_to_cell_vecs(struct TheoryVec *cell_vecs, int cell_vec_coun /* Sort in order to get most agreeable matches first */ qsort(for_sort, count, sizeof(struct sortme), sort_theory_distances); - *match_array = malloc(count*sizeof(struct TheoryVec)); + *match_array = cfmalloc(count*sizeof(struct TheoryVec)); *match_count = count; for ( j=0; j<count; j++ ) { (*match_array)[j] = for_sort[j].v; } - free(for_sort); + cffree(for_sort); } return 1; @@ -1806,8 +1806,8 @@ static int gen_observed_vecs(struct rvec *rlps, int rlp_count, count++; struct SpotVec *temp_obs_vecs; - temp_obs_vecs = realloc(cell->obs_vecs, - count*sizeof(struct SpotVec)); + temp_obs_vecs = cfrealloc(cell->obs_vecs, + count*sizeof(struct SpotVec)); if ( temp_obs_vecs == NULL ) { return 0; @@ -1899,8 +1899,8 @@ static int gen_theoretical_vecs(UnitCell *cell, struct TheoryVec **cell_vecs, count++; struct TheoryVec *temp_cell_vecs; - temp_cell_vecs = realloc(*cell_vecs, - count*sizeof(struct TheoryVec)); + temp_cell_vecs = cfrealloc(*cell_vecs, + count*sizeof(struct TheoryVec)); if ( temp_cell_vecs == NULL ) { return 0; @@ -1929,10 +1929,10 @@ static void cleanup_taketwo_obs_vecs(struct SpotVec *obs_vecs, { int i; for ( i=0; i<obs_vec_count; i++ ) { - free(obs_vecs[i].matches); + cffree(obs_vecs[i].matches); } - free(obs_vecs); + cffree(obs_vecs); } static void cleanup_taketwo_cell(struct TakeTwoCell *ttCell) @@ -1943,7 +1943,7 @@ static void cleanup_taketwo_cell(struct TakeTwoCell *ttCell) for ( i=0; i<ttCell->numOps; i++ ) { gsl_matrix_free(ttCell->rotSymOps[i]); } - free(ttCell->rotSymOps); + cffree(ttCell->rotSymOps); cleanup_taketwo_obs_vecs(ttCell->obs_vecs, ttCell->obs_vec_count); @@ -2056,12 +2056,12 @@ static UnitCell *run_taketwo(UnitCell *cell, const struct taketwo_options *opts, /* Add the current solution to the previous solutions list */ int new_size = (tp->numPrevs + 1) * sizeof(gsl_matrix *); - gsl_matrix **tmp = realloc(tp->prevSols, new_size); - double *tmpScores = realloc(tp->prevScores, + gsl_matrix **tmp = cfrealloc(tp->prevSols, new_size); + double *tmpScores = cfrealloc(tp->prevScores, (tp->numPrevs + 1) * sizeof(double)); unsigned int *tmpSuccesses; - tmpSuccesses = realloc(tp->membership, - (tp->numPrevs + 1) * sizeof(unsigned int)); + tmpSuccesses = cfrealloc(tp->membership, + (tp->numPrevs + 1) * sizeof(unsigned int)); if (!tmp) { apologise(); @@ -2096,11 +2096,11 @@ static void partial_taketwo_cleanup(struct taketwo_private *tp) gsl_matrix_free(tp->prevSols[i]); } - free(tp->prevSols); + cffree(tp->prevSols); } - free(tp->prevScores); - free(tp->membership); + cffree(tp->prevScores); + cffree(tp->membership); tp->prevScores = NULL; tp->membership = NULL; tp->xtal_num = 0; @@ -2143,7 +2143,7 @@ int taketwo_index(struct image *image, void *priv) tp->xtal_num = image->n_crystals; } - rlps = malloc((image_feature_count(image->features)+1)*sizeof(struct rvec)); + rlps = cfmalloc((image_feature_count(image->features)+1)*sizeof(struct rvec)); for ( i=0; i<image_feature_count(image->features); i++ ) { double r[3]; @@ -2164,7 +2164,7 @@ int taketwo_index(struct image *image, void *priv) rlps[n_rlps++].w = 0.0; cell = run_taketwo(tp->cell, tp->opts, rlps, n_rlps, tp); - free(rlps); + cffree(rlps); if ( cell == NULL ) return 0; cr = crystal_new(); @@ -2222,7 +2222,7 @@ void *taketwo_prepare(IndexingMethod *indm, struct taketwo_options *opts, STATUS("\n"); - tp = malloc(sizeof(struct taketwo_private)); + tp = cfmalloc(sizeof(struct taketwo_private)); if ( tp == NULL ) return NULL; tp->cell = cell; @@ -2248,9 +2248,9 @@ void taketwo_cleanup(IndexingPrivate *pp) struct taketwo_private *tp = (struct taketwo_private *)pp; partial_taketwo_cleanup(tp); - free(tp->theory_vecs); + cffree(tp->theory_vecs); - free(tp); + cffree(tp); } @@ -2280,7 +2280,7 @@ int taketwo_default_options(struct taketwo_options **opts_ptr) { struct taketwo_options *opts; - opts = malloc(sizeof(struct taketwo_options)); + opts = cfmalloc(sizeof(struct taketwo_options)); if ( opts == NULL ) return ENOMEM; opts->member_thresh = -1.0; opts->len_tol = -1.0; diff --git a/libcrystfel/src/indexers/xds.c b/libcrystfel/src/indexers/xds.c index 8ef496cf..23274dc4 100644 --- a/libcrystfel/src/indexers/xds.c +++ b/libcrystfel/src/indexers/xds.c @@ -468,7 +468,7 @@ void *xds_prepare(IndexingMethod *indm, UnitCell *cell) return NULL; } - xp = calloc(1, sizeof(*xp)); + xp = cfcalloc(1, sizeof(*xp)); if ( xp == NULL ) return NULL; /* Flags that XDS knows about */ @@ -487,7 +487,7 @@ void xds_cleanup(void *pp) struct xds_private *xp; xp = (struct xds_private *)pp; - free(xp); + cffree(xp); } diff --git a/libcrystfel/src/indexers/xgandalf.c b/libcrystfel/src/indexers/xgandalf.c index 6c50a38b..defef243 100644 --- a/libcrystfel/src/indexers/xgandalf.c +++ b/libcrystfel/src/indexers/xgandalf.c @@ -158,7 +158,7 @@ int run_xgandalf(struct image *image, void *ipriv) void *xgandalf_prepare(IndexingMethod *indm, UnitCell *cell, struct xgandalf_options *xgandalf_opts) { - struct xgandalf_private_data *xgandalf_private_data = malloc(sizeof(struct xgandalf_private_data)); + struct xgandalf_private_data *xgandalf_private_data = cfmalloc(sizeof(struct xgandalf_private_data)); allocReciprocalPeaks(&(xgandalf_private_data->reciprocalPeaks_1_per_A)); xgandalf_private_data->indm = *indm; xgandalf_private_data->cellTemplate = NULL; @@ -264,7 +264,7 @@ void xgandalf_cleanup(void *pp) if(xgandalf_private_data->centeringTransformation != NULL){ intmat_free(xgandalf_private_data->centeringTransformation); } - free(xgandalf_private_data); + cffree(xgandalf_private_data); } static void reduceCell(UnitCell *cell, LatticeTransform_t* appliedReductionTransform) @@ -382,7 +382,7 @@ int xgandalf_default_options(struct xgandalf_options **opts_ptr) { struct xgandalf_options *opts; - opts = malloc(sizeof(struct xgandalf_options)); + opts = cfmalloc(sizeof(struct xgandalf_options)); if ( opts == NULL ) return ENOMEM; opts->sampling_pitch = 6; diff --git a/libcrystfel/src/integer_matrix.c b/libcrystfel/src/integer_matrix.c index c6527d82..f7881d0a 100644 --- a/libcrystfel/src/integer_matrix.c +++ b/libcrystfel/src/integer_matrix.c @@ -62,12 +62,12 @@ IntegerMatrix *intmat_new(unsigned int rows, unsigned int cols) { IntegerMatrix *m; - m = malloc(sizeof(IntegerMatrix)); + m = cfmalloc(sizeof(IntegerMatrix)); if ( m == NULL ) return NULL; - m->v = calloc(rows*cols, sizeof(signed int)); + m->v = cfcalloc(rows*cols, sizeof(signed int)); if ( m->v == NULL ) { - free(m); + cffree(m); return NULL; } @@ -109,8 +109,8 @@ IntegerMatrix *intmat_copy(const IntegerMatrix *m) void intmat_free(IntegerMatrix *m) { if ( m == NULL ) return; - free(m->v); - free(m); + cffree(m->v); + cffree(m); } @@ -190,7 +190,7 @@ signed int *transform_indices(const IntegerMatrix *P, const signed int *hkl) signed int *ans; unsigned int j; - ans = malloc(P->rows * sizeof(signed int)); + ans = cfmalloc(P->rows * sizeof(signed int)); if ( ans == NULL ) return NULL; for ( j=0; j<P->cols; j++ ) { diff --git a/libcrystfel/src/integration.c b/libcrystfel/src/integration.c index 3912114a..cad0a75c 100644 --- a/libcrystfel/src/integration.c +++ b/libcrystfel/src/integration.c @@ -393,7 +393,7 @@ static int alloc_boxes(struct intcontext *ic, int new_max_boxes) { struct peak_box *boxes_new; - boxes_new = realloc(ic->boxes, sizeof(struct peak_box)*new_max_boxes); + boxes_new = cfrealloc(ic->boxes, sizeof(struct peak_box)*new_max_boxes); if ( boxes_new == NULL ) return 1; ic->boxes = boxes_new; @@ -467,7 +467,7 @@ struct intcontext *intcontext_new(struct image *image, int i; struct intcontext *ic; - ic = malloc(sizeof(struct intcontext)); + ic = cfmalloc(sizeof(struct intcontext)); if ( ic == NULL ) return NULL; ic->halfw = ir_out; @@ -481,36 +481,36 @@ struct intcontext *intcontext_new(struct image *image, ic->int_diag = INTDIAG_NONE; ic->w = 2*ic->halfw + 1; - ic->bm = malloc(ic->w * ic->w * sizeof(enum boxmask_val)); + ic->bm = cfmalloc(ic->w * ic->w * sizeof(enum boxmask_val)); if ( ic->bm == NULL ) { ERROR("Failed to allocate box mask.\n"); - free(ic); + cffree(ic); return NULL; } /* How many reference profiles? */ ic->n_reference_profiles = 1; - ic->reference_profiles = calloc(ic->n_reference_profiles, - sizeof(double *)); + ic->reference_profiles = cfcalloc(ic->n_reference_profiles, + sizeof(double *)); if ( ic->reference_profiles == NULL ) { - free(ic); + cffree(ic); return NULL; } - ic->reference_den = calloc(ic->n_reference_profiles, sizeof(double *)); + ic->reference_den = cfcalloc(ic->n_reference_profiles, sizeof(double *)); if ( ic->reference_den == NULL ) { - free(ic); + cffree(ic); return NULL; } - ic->n_profiles_in_reference = calloc(ic->n_reference_profiles, - sizeof(int)); + ic->n_profiles_in_reference = cfcalloc(ic->n_reference_profiles, + sizeof(int)); if ( ic->n_profiles_in_reference == NULL ) { - free(ic); + cffree(ic); return NULL; } for ( i=0; i<ic->n_reference_profiles; i++ ) { - ic->reference_profiles[i] = malloc(ic->w*ic->w*sizeof(double)); + ic->reference_profiles[i] = cfmalloc(ic->w*ic->w*sizeof(double)); if ( ic->reference_profiles[i] == NULL ) return NULL; - ic->reference_den[i] = malloc(ic->w*ic->w*sizeof(double)); + ic->reference_den[i] = cfmalloc(ic->w*ic->w*sizeof(double)); if ( ic->reference_den[i] == NULL ) return NULL; } zero_profiles(ic); @@ -519,7 +519,7 @@ struct intcontext *intcontext_new(struct image *image, ic->n_boxes = 0; ic->max_boxes = 0; if ( alloc_boxes(ic, 32) ) { - free(ic); + cffree(ic); return NULL; } @@ -534,20 +534,20 @@ void intcontext_free(struct intcontext *ic) int i; for ( i=0; i<ic->n_boxes; i++ ) { - free(ic->boxes[i].bm); + cffree(ic->boxes[i].bm); gsl_matrix_free(ic->boxes[i].bgm); } - free(ic->boxes); + cffree(ic->boxes); for ( i=0; i<ic->n_reference_profiles; i++ ) { - free(ic->reference_profiles[i]); - free(ic->reference_den[i]); - } - free(ic->reference_profiles); - free(ic->reference_den); - free(ic->n_profiles_in_reference); - free(ic->bm); - free(ic); + cffree(ic->reference_profiles[i]); + cffree(ic->reference_den[i]); + } + cffree(ic->reference_profiles); + cffree(ic->reference_den); + cffree(ic->n_profiles_in_reference); + cffree(ic->bm); + cffree(ic); } @@ -604,7 +604,7 @@ static void delete_box(struct intcontext *ic, struct peak_box *bx) return; } - free(bx->bm); + cffree(bx->bm); gsl_matrix_free(bx->bgm); memmove(&ic->boxes[i], &ic->boxes[i+1], @@ -803,7 +803,7 @@ static int check_box(struct intcontext *ic, struct peak_box *bx, int *sat) if ( sat != NULL ) *sat = 0; - bx->bm = malloc(ic->w*ic->w*sizeof(enum boxmask_val)); + bx->bm = cfmalloc(ic->w*ic->w*sizeof(enum boxmask_val)); if ( bx->bm == NULL ) { ERROR("Failed to allocate box mask\n"); return 1; @@ -980,7 +980,7 @@ static int center_and_check_box(struct intcontext *ic, struct peak_box *bx, t_offs_fs += ifs; t_offs_ss += iss; - free(bx->bm); + cffree(bx->bm); if ( check_box(ic, bx, sat) ) { return 1; } @@ -1515,7 +1515,7 @@ static double estimate_resolution(Crystal *cr, struct image *image) UnitCell *cell; - acc = malloc(max_acc*sizeof(double)); + acc = cfmalloc(max_acc*sizeof(double)); if ( acc == NULL ) { ERROR("Allocation failed during estimate_resolution!\n"); return INFINITY; @@ -1577,7 +1577,7 @@ static double estimate_resolution(Crystal *cr, struct image *image) if ( n_acc < 3 ) { STATUS("WARNING: Too few peaks to estimate resolution.\n"); - free(acc); + cffree(acc); return 0.0; } @@ -1587,7 +1587,7 @@ static double estimate_resolution(Crystal *cr, struct image *image) if ( n < 2 ) n = 2; max_res = acc[(n_acc-1)-n]; - free(acc); + cffree(acc); return max_res; } @@ -1711,7 +1711,7 @@ void integrate_all_5(struct image *image, IntegrationMethod meth, } for ( i=0; i<image->detgeom->n_panels; i++ ) { - free(masks[i]); + cffree(masks[i]); } } @@ -1794,7 +1794,7 @@ char *str_integration_method(IntegrationMethod m) strcat(tmp, "-grad"); } - return strdup(tmp); + return cfstrdup(tmp); } @@ -1854,10 +1854,10 @@ IntegrationMethod integration_method(const char *str, int *err) return INTEGRATION_NONE; } - free(methods[i]); + cffree(methods[i]); } - free(methods); + cffree(methods); return meth; diff --git a/libcrystfel/src/peakfinder8.c b/libcrystfel/src/peakfinder8.c index 4c41040a..95153191 100644 --- a/libcrystfel/src/peakfinder8.c +++ b/libcrystfel/src/peakfinder8.c @@ -119,26 +119,26 @@ static struct radial_stats_pixels *compute_rstats_pixels(struct radius_maps *rma int i; struct radial_stats_pixels *rsp = NULL; - rsp = (struct radial_stats_pixels *)malloc(sizeof(struct radial_stats_pixels)); + rsp = (struct radial_stats_pixels *)cfmalloc(sizeof(struct radial_stats_pixels)); if ( rsp == NULL ) { return NULL; } - rsp->n_pixels = (int *)malloc(rmaps->n_rmaps * sizeof(int)); + rsp->n_pixels = (int *)cfmalloc(rmaps->n_rmaps * sizeof(int)); if ( rsp->n_pixels == NULL ) { - free(rsp); + cffree(rsp); return NULL; } - rsp->pidx = (int **)malloc(rmaps->n_rmaps * sizeof(int *)); + rsp->pidx = (int **)cfmalloc(rmaps->n_rmaps * sizeof(int *)); if ( rsp->pidx == NULL ) { - free(rsp->n_pixels); - free(rsp); + cffree(rsp->n_pixels); + cffree(rsp); return NULL; } - rsp->radius = (int **)malloc(rmaps->n_rmaps * sizeof(int *)); + rsp->radius = (int **)cfmalloc(rmaps->n_rmaps * sizeof(int *)); if ( rsp->radius == NULL ) { - free(rsp->n_pixels); - free(rsp->pidx); - free(rsp); + cffree(rsp->n_pixels); + cffree(rsp->pidx); + cffree(rsp); return NULL; } srand(0); @@ -147,16 +147,16 @@ static struct radial_stats_pixels *compute_rstats_pixels(struct radius_maps *rma // Assuming 5000 is the maximum possible radius int n_bins = 5000; - int *n_pixels = (int *)malloc(n_bins * sizeof(int)); // selected pixels per bin - int *n_tot_pixels = (int *)malloc(n_bins * sizeof(int));; // total pixels per bin - int **panel = (int **)malloc(n_bins * sizeof(int *)); // panel ID of selected pixels - int **idx = (int **)malloc(n_bins * sizeof(int *)); // index of selected pixels + int *n_pixels = (int *)cfmalloc(n_bins * sizeof(int)); // selected pixels per bin + int *n_tot_pixels = (int *)cfmalloc(n_bins * sizeof(int));; // total pixels per bin + int **panel = (int **)cfmalloc(n_bins * sizeof(int *)); // panel ID of selected pixels + int **idx = (int **)cfmalloc(n_bins * sizeof(int *)); // index of selected pixels for ( i = 0; i < n_bins; i++ ) { n_pixels[i] = 0; n_tot_pixels[i] = 0; - panel[i] = (int *)malloc(n_pixels_per_bin * sizeof(int)); - idx[i] = (int *)malloc(n_pixels_per_bin * sizeof(int)); + panel[i] = (int *)cfmalloc(n_pixels_per_bin * sizeof(int)); + idx[i] = (int *)cfmalloc(n_pixels_per_bin * sizeof(int)); } int radius; @@ -186,40 +186,40 @@ static struct radial_stats_pixels *compute_rstats_pixels(struct radius_maps *rma } } - int *sidx = (int *)malloc(rmaps->n_rmaps * sizeof(int)); + int *sidx = (int *)cfmalloc(rmaps->n_rmaps * sizeof(int)); if ( sidx == NULL ) { - free(rsp->n_pixels); - free(rsp->pidx); - free(rsp->radius); - free(rsp); + cffree(rsp->n_pixels); + cffree(rsp->pidx); + cffree(rsp->radius); + cffree(rsp); return NULL; } for ( p = 0; p < rmaps->n_rmaps; p++ ) { - rsp->pidx[p] = (int *)malloc(rsp->n_pixels[p] * sizeof(int)); + rsp->pidx[p] = (int *)cfmalloc(rsp->n_pixels[p] * sizeof(int)); if ( rsp->pidx[p] == NULL ) { for ( i = 0; i < p; i++ ) { - free(rsp->pidx[i]); - free(rsp->radius[i]); + cffree(rsp->pidx[i]); + cffree(rsp->radius[i]); } - free(rsp->pidx); - free(rsp->radius); - free(rsp->n_pixels); - free(rsp); - free(sidx); + cffree(rsp->pidx); + cffree(rsp->radius); + cffree(rsp->n_pixels); + cffree(rsp); + cffree(sidx); return NULL; } - rsp->radius[p] = (int *)malloc(rsp->n_pixels[p] * sizeof(int)); + rsp->radius[p] = (int *)cfmalloc(rsp->n_pixels[p] * sizeof(int)); if ( rsp->radius[p] == NULL ) { for ( i = 0; i < p; i++ ) { - free(rsp->pidx[i]); - free(rsp->radius[i]); + cffree(rsp->pidx[i]); + cffree(rsp->radius[i]); } - free(rsp->pidx[p]); - free(rsp->pidx); - free(rsp->radius); - free(rsp->n_pixels); - free(rsp); - free(sidx); + cffree(rsp->pidx[p]); + cffree(rsp->pidx); + cffree(rsp->radius); + cffree(rsp->n_pixels); + cffree(rsp); + cffree(sidx); return NULL; } sidx[p] = 0; @@ -233,15 +233,15 @@ static struct radial_stats_pixels *compute_rstats_pixels(struct radius_maps *rma sidx[p] += 1; } } - free(sidx); + cffree(sidx); for ( i = 0; i < n_bins; i++ ) { - free(panel[i]); - free(idx[i]); + cffree(panel[i]); + cffree(idx[i]); } - free(panel); - free(idx); - free(n_pixels); - free(n_tot_pixels); + cffree(panel); + cffree(idx); + cffree(n_pixels); + cffree(n_tot_pixels); rsp->n_panels = rmaps->n_rmaps; return rsp; @@ -251,13 +251,13 @@ static void free_rstats_pixels(struct radial_stats_pixels *rsp) { int i; for ( i = 0; i < rsp->n_panels; i++ ) { - free(rsp->pidx[i]); - free(rsp->radius[i]); + cffree(rsp->pidx[i]); + cffree(rsp->radius[i]); } - free(rsp->pidx); - free(rsp->radius); - free(rsp->n_pixels); - free(rsp); + cffree(rsp->pidx); + cffree(rsp->radius); + cffree(rsp->n_pixels); + cffree(rsp); } @@ -267,20 +267,20 @@ static struct radius_maps *compute_radius_maps(struct detgeom *det) struct detgeom_panel p; struct radius_maps *rm = NULL; - rm = (struct radius_maps *)malloc(sizeof(struct radius_maps)); + rm = (struct radius_maps *)cfmalloc(sizeof(struct radius_maps)); if ( rm == NULL ) { return NULL; } - rm->r_maps = (float **)malloc(det->n_panels*sizeof(float*)); + rm->r_maps = (float **)cfmalloc(det->n_panels*sizeof(float*)); if ( rm->r_maps == NULL ) { - free(rm); + cffree(rm); return NULL; } - rm->n_pixels = (int *)malloc(det->n_panels*sizeof(int*)); + rm->n_pixels = (int *)cfmalloc(det->n_panels*sizeof(int*)); if ( rm->r_maps == NULL ) { - free(rm); + cffree(rm); return NULL; } @@ -289,13 +289,13 @@ static struct radius_maps *compute_radius_maps(struct detgeom *det) for( i=0 ; i<det->n_panels ; i++ ) { p = det->panels[i]; - rm->r_maps[i] = (float *)malloc(p.h*p.w*sizeof(float)); + rm->r_maps[i] = (float *)cfmalloc(p.h*p.w*sizeof(float)); if ( rm->r_maps[i] == NULL ) { for ( u = 0; u<i; u++ ) { - free(rm->r_maps[u]); + cffree(rm->r_maps[u]); } - free(rm); + cffree(rm); return NULL; } rm->n_pixels[i] = p.h * p.w; @@ -323,11 +323,11 @@ static void free_radius_maps(struct radius_maps *r_maps) int i; for ( i=0 ; i<r_maps->n_rmaps ; i++ ) { - free(r_maps->r_maps[i]); + cffree(r_maps->r_maps[i]); } - free(r_maps->r_maps); - free(r_maps->n_pixels); - free(r_maps); + cffree(r_maps->r_maps); + cffree(r_maps->n_pixels); + cffree(r_maps); } @@ -339,13 +339,13 @@ struct pf8_private_data *prepare_peakfinder8(struct detgeom *det, int fast_mode) return NULL; } - data = (struct pf8_private_data *)malloc(sizeof(struct pf8_private_data)); + data = (struct pf8_private_data *)cfmalloc(sizeof(struct pf8_private_data)); if ( data == NULL ) { return NULL; } data->rmaps = compute_radius_maps(det); if ( data->rmaps == NULL ) { - free(data); + cffree(data); return NULL; } if ( fast_mode ) { @@ -369,7 +369,7 @@ void free_pf8_private_data(struct pf8_private_data *data) if ( data->fast_mode ) { free_rstats_pixels(data->rpixels); } - free(data); + cffree(data); } @@ -381,8 +381,8 @@ static struct peakfinder_mask *create_peakfinder_mask(struct image *img, int i; struct peakfinder_mask *msk; - msk = (struct peakfinder_mask *)malloc(sizeof(struct peakfinder_mask)); - msk->masks =(char **) malloc(img->detgeom->n_panels*sizeof(char*)); + msk = (struct peakfinder_mask *)cfmalloc(sizeof(struct peakfinder_mask)); + msk->masks =(char **) cfmalloc(img->detgeom->n_panels*sizeof(char*)); msk->n_masks = img->detgeom->n_panels; for ( i=0; i<img->detgeom->n_panels; i++) { @@ -391,7 +391,7 @@ static struct peakfinder_mask *create_peakfinder_mask(struct image *img, p = img->detgeom->panels[i]; - msk->masks[i] = (char *)calloc(p.w*p.h,sizeof(char)); + msk->masks[i] = (char *)cfcalloc(p.w*p.h,sizeof(char)); for ( iss=0 ; iss<p.h ; iss++ ) { for ( ifs=0 ; ifs<p.w ; ifs++ ) { @@ -422,10 +422,10 @@ static void free_peakfinder_mask(struct peakfinder_mask * pfmask) int i; for ( i=0 ; i<pfmask->n_masks ; i++ ) { - free(pfmask->masks[i]); + cffree(pfmask->masks[i]); } - free(pfmask->masks); - free(pfmask); + cffree(pfmask->masks); + cffree(pfmask); } @@ -434,29 +434,29 @@ static struct peakfinder_panel_data *allocate_panel_data(int num_panels) struct peakfinder_panel_data *pfdata; - pfdata = (struct peakfinder_panel_data *)malloc(sizeof(struct peakfinder_panel_data)); + pfdata = (struct peakfinder_panel_data *)cfmalloc(sizeof(struct peakfinder_panel_data)); if ( pfdata == NULL ) { return NULL; } - pfdata->panel_h = (int *)malloc(num_panels*sizeof(int)); + pfdata->panel_h = (int *)cfmalloc(num_panels*sizeof(int)); if ( pfdata->panel_h == NULL ) { - free(pfdata); + cffree(pfdata); return NULL; } - pfdata->panel_w = (int *)malloc(num_panels*sizeof(int)); + pfdata->panel_w = (int *)cfmalloc(num_panels*sizeof(int)); if ( pfdata->panel_w == NULL ) { - free(pfdata->panel_h); - free(pfdata); + cffree(pfdata->panel_h); + cffree(pfdata); return NULL; } - pfdata->panel_data = (float **)malloc(num_panels*sizeof(float*)); + pfdata->panel_data = (float **)cfmalloc(num_panels*sizeof(float*)); if ( pfdata->panel_data == NULL ) { - free(pfdata->panel_w); - free(pfdata->panel_h); - free(pfdata); + cffree(pfdata->panel_w); + cffree(pfdata->panel_h); + cffree(pfdata); return NULL; } @@ -468,10 +468,10 @@ static struct peakfinder_panel_data *allocate_panel_data(int num_panels) static void free_panel_data(struct peakfinder_panel_data *pfdata) { - free(pfdata->panel_data); - free(pfdata->panel_w); - free(pfdata->panel_h); - free(pfdata); + cffree(pfdata->panel_data); + cffree(pfdata->panel_w); + cffree(pfdata->panel_h); + cffree(pfdata); } @@ -496,48 +496,48 @@ static struct radial_stats* allocate_radial_stats(int num_rad_bins) { struct radial_stats* rstats; - rstats = (struct radial_stats *)malloc(sizeof(struct radial_stats)); + rstats = (struct radial_stats *)cfmalloc(sizeof(struct radial_stats)); if ( rstats == NULL ) { return NULL; } - rstats->roffset = (float *)malloc(num_rad_bins*sizeof(float)); + rstats->roffset = (float *)cfmalloc(num_rad_bins*sizeof(float)); if ( rstats->roffset == NULL ) { - free(rstats); + cffree(rstats); return NULL; } - rstats->rthreshold = (float *)malloc(num_rad_bins*sizeof(float)); + rstats->rthreshold = (float *)cfmalloc(num_rad_bins*sizeof(float)); if ( rstats->rthreshold == NULL ) { - free(rstats->roffset); - free(rstats); + cffree(rstats->roffset); + cffree(rstats); return NULL; } - rstats->lthreshold = (float *)malloc(num_rad_bins*sizeof(float)); + rstats->lthreshold = (float *)cfmalloc(num_rad_bins*sizeof(float)); if ( rstats->lthreshold == NULL ) { - free(rstats->rthreshold); - free(rstats->roffset); - free(rstats); + cffree(rstats->rthreshold); + cffree(rstats->roffset); + cffree(rstats); return NULL; } - rstats->rsigma = (float *)malloc(num_rad_bins*sizeof(float)); + rstats->rsigma = (float *)cfmalloc(num_rad_bins*sizeof(float)); if ( rstats->rsigma == NULL ) { - free(rstats->roffset); - free(rstats->rthreshold); - free(rstats->lthreshold); - free(rstats); + cffree(rstats->roffset); + cffree(rstats->rthreshold); + cffree(rstats->lthreshold); + cffree(rstats); return NULL; } - rstats->rcount = (int *)malloc(num_rad_bins*sizeof(int)); + rstats->rcount = (int *)cfmalloc(num_rad_bins*sizeof(int)); if ( rstats->rcount == NULL ) { - free(rstats->roffset); - free(rstats->rthreshold); - free(rstats->lthreshold); - free(rstats->rsigma); - free(rstats); + cffree(rstats->roffset); + cffree(rstats->rthreshold); + cffree(rstats->lthreshold); + cffree(rstats->rsigma); + cffree(rstats); return NULL; } @@ -549,12 +549,12 @@ static struct radial_stats* allocate_radial_stats(int num_rad_bins) static void free_radial_stats(struct radial_stats *rstats) { - free(rstats->roffset); - free(rstats->rthreshold); - free(rstats->lthreshold); - free(rstats->rsigma); - free(rstats->rcount); - free(rstats); + cffree(rstats->roffset); + cffree(rstats->rthreshold); + cffree(rstats->lthreshold); + cffree(rstats->rsigma); + cffree(rstats->rcount); + cffree(rstats); } @@ -663,85 +663,85 @@ struct peakfinder_peak_data *allocate_peak_data(int max_num_peaks) { struct peakfinder_peak_data *pkdata; - pkdata = (struct peakfinder_peak_data*)malloc(sizeof(struct peakfinder_peak_data)); + pkdata = (struct peakfinder_peak_data*)cfmalloc(sizeof(struct peakfinder_peak_data)); if ( pkdata == NULL ) { return NULL; } - pkdata->npix = (int *)malloc(max_num_peaks*sizeof(int)); + pkdata->npix = (int *)cfmalloc(max_num_peaks*sizeof(int)); if ( pkdata->npix == NULL ) { - free(pkdata->npix); - free(pkdata); + cffree(pkdata->npix); + cffree(pkdata); return NULL; } - pkdata->com_fs = (float *)malloc(max_num_peaks*sizeof(float)); + pkdata->com_fs = (float *)cfmalloc(max_num_peaks*sizeof(float)); if ( pkdata->com_fs == NULL ) { - free(pkdata->npix); - free(pkdata); + cffree(pkdata->npix); + cffree(pkdata); return NULL; } - pkdata->com_ss = (float *)malloc(max_num_peaks*sizeof(float)); + pkdata->com_ss = (float *)cfmalloc(max_num_peaks*sizeof(float)); if ( pkdata->com_ss == NULL ) { - free(pkdata->npix); - free(pkdata->com_fs); - free(pkdata); + cffree(pkdata->npix); + cffree(pkdata->com_fs); + cffree(pkdata); return NULL; } - pkdata->com_index = (int *)malloc(max_num_peaks*sizeof(int)); + pkdata->com_index = (int *)cfmalloc(max_num_peaks*sizeof(int)); if ( pkdata->com_ss == NULL ) { - free(pkdata->npix); - free(pkdata->com_fs); - free(pkdata->com_ss); - free(pkdata); + cffree(pkdata->npix); + cffree(pkdata->com_fs); + cffree(pkdata->com_ss); + cffree(pkdata); return NULL; } - pkdata->tot_i = (float *)malloc(max_num_peaks*sizeof(float)); + pkdata->tot_i = (float *)cfmalloc(max_num_peaks*sizeof(float)); if ( pkdata->tot_i == NULL ) { - free(pkdata->npix); - free(pkdata->com_fs); - free(pkdata->com_ss); - free(pkdata->com_index); - free(pkdata); + cffree(pkdata->npix); + cffree(pkdata->com_fs); + cffree(pkdata->com_ss); + cffree(pkdata->com_index); + cffree(pkdata); return NULL; } - pkdata->max_i = (float *)malloc(max_num_peaks*sizeof(float)); + pkdata->max_i = (float *)cfmalloc(max_num_peaks*sizeof(float)); if ( pkdata->max_i == NULL ) { - free(pkdata->npix); - free(pkdata->com_fs); - free(pkdata->com_ss); - free(pkdata->com_index); - free(pkdata->tot_i); - free(pkdata); + cffree(pkdata->npix); + cffree(pkdata->com_fs); + cffree(pkdata->com_ss); + cffree(pkdata->com_index); + cffree(pkdata->tot_i); + cffree(pkdata); return NULL; } - pkdata->sigma = (float *)malloc(max_num_peaks*sizeof(float)); + pkdata->sigma = (float *)cfmalloc(max_num_peaks*sizeof(float)); if ( pkdata->sigma == NULL ) { - free(pkdata->npix); - free(pkdata->com_fs); - free(pkdata->com_ss); - free(pkdata->com_index); - free(pkdata->tot_i); - free(pkdata->max_i); - free(pkdata); + cffree(pkdata->npix); + cffree(pkdata->com_fs); + cffree(pkdata->com_ss); + cffree(pkdata->com_index); + cffree(pkdata->tot_i); + cffree(pkdata->max_i); + cffree(pkdata); return NULL; } - pkdata->snr = (float *)malloc(max_num_peaks*sizeof(float)); + pkdata->snr = (float *)cfmalloc(max_num_peaks*sizeof(float)); if ( pkdata->snr == NULL ) { - free(pkdata->npix); - free(pkdata->com_fs); - free(pkdata->com_ss); - free(pkdata->com_index); - free(pkdata->tot_i); - free(pkdata->max_i); - free(pkdata->sigma); - free(pkdata); + cffree(pkdata->npix); + cffree(pkdata->com_fs); + cffree(pkdata->com_ss); + cffree(pkdata->com_index); + cffree(pkdata->tot_i); + cffree(pkdata->max_i); + cffree(pkdata->sigma); + cffree(pkdata); return NULL; } @@ -750,15 +750,15 @@ struct peakfinder_peak_data *allocate_peak_data(int max_num_peaks) static void free_peak_data(struct peakfinder_peak_data *pkdata) { - free(pkdata->npix); - free(pkdata->com_fs); - free(pkdata->com_ss); - free(pkdata->com_index); - free(pkdata->tot_i); - free(pkdata->max_i); - free(pkdata->sigma); - free(pkdata->snr); - free(pkdata); + cffree(pkdata->npix); + cffree(pkdata->com_fs); + cffree(pkdata->com_ss); + cffree(pkdata->com_index); + cffree(pkdata->tot_i); + cffree(pkdata->max_i); + cffree(pkdata->sigma); + cffree(pkdata->snr); + cffree(pkdata); } @@ -768,38 +768,38 @@ static struct peakfinder_intern_data *allocate_peakfinder_intern_data(int data_s struct peakfinder_intern_data *intern_data; - intern_data = (struct peakfinder_intern_data *)malloc(sizeof(struct peakfinder_intern_data)); + intern_data = (struct peakfinder_intern_data *)cfmalloc(sizeof(struct peakfinder_intern_data)); if ( intern_data == NULL ) { return NULL; } - intern_data->pix_in_peak_map =(char *)calloc(data_size, sizeof(char)); + intern_data->pix_in_peak_map =(char *)cfcalloc(data_size, sizeof(char)); if ( intern_data->pix_in_peak_map == NULL ) { - free(intern_data); + cffree(intern_data); return NULL; } - intern_data->infs =(int *)calloc(data_size, sizeof(int)); + intern_data->infs =(int *)cfcalloc(data_size, sizeof(int)); if ( intern_data->infs == NULL ) { - free(intern_data->pix_in_peak_map); - free(intern_data); + cffree(intern_data->pix_in_peak_map); + cffree(intern_data); return NULL; } - intern_data->inss =(int *)calloc(data_size, sizeof(int)); + intern_data->inss =(int *)cfcalloc(data_size, sizeof(int)); if ( intern_data->inss == NULL ) { - free(intern_data->pix_in_peak_map); - free(intern_data->infs); - free(intern_data); + cffree(intern_data->pix_in_peak_map); + cffree(intern_data->infs); + cffree(intern_data); return NULL; } - intern_data->peak_pixels =(int *)calloc(max_pix_count, sizeof(int)); + intern_data->peak_pixels =(int *)cfcalloc(max_pix_count, sizeof(int)); if ( intern_data->peak_pixels == NULL ) { - free(intern_data->pix_in_peak_map); - free(intern_data->infs); - free(intern_data->inss); - free(intern_data); + cffree(intern_data->pix_in_peak_map); + cffree(intern_data->infs); + cffree(intern_data->inss); + cffree(intern_data); return NULL; } @@ -809,11 +809,11 @@ static struct peakfinder_intern_data *allocate_peakfinder_intern_data(int data_s static void free_peakfinder_intern_data(struct peakfinder_intern_data *pfid) { - free(pfid->peak_pixels); - free(pfid->pix_in_peak_map); - free(pfid->infs); - free(pfid->inss); - free(pfid); + cffree(pfid->peak_pixels); + cffree(pfid->pix_in_peak_map); + cffree(pfid->infs); + cffree(pfid->inss); + cffree(pfid); } diff --git a/libcrystfel/src/peaks.c b/libcrystfel/src/peaks.c index 6de36e4a..d56f6d03 100644 --- a/libcrystfel/src/peaks.c +++ b/libcrystfel/src/peaks.c @@ -115,7 +115,7 @@ int *make_BgMask(struct image *image, struct detgeom_panel *p, int *mask; int i; - mask = calloc(p->w*p->h, sizeof(int)); + mask = cfcalloc(p->w*p->h, sizeof(int)); if ( mask == NULL ) return NULL; if ( image->crystals == NULL ) return mask; @@ -524,10 +524,10 @@ int search_peaks_peakfinder9(struct image *image, float min_snr_biggest_pix, det_size_one_panel.pix_ny = h; det_size_one_panel.pix_nn = w * h; - data_copy_new = realloc(data_copy, w*h*sizeof(*data_copy)); + data_copy_new = cfrealloc(data_copy, w*h*sizeof(*data_copy)); if ( data_copy_new == NULL ) { if ( data_copy != NULL ) { - free(data_copy); + cffree(data_copy); } freePeakList(peakList); return 1; @@ -555,7 +555,7 @@ int search_peaks_peakfinder9(struct image *image, float min_snr_biggest_pix, } freePeakList(peakList); - free(data_copy); + cffree(data_copy); return 0; } @@ -747,7 +747,7 @@ double estimate_peak_resolution(ImageFeatureList *peaks, double lambda, /* No peaks -> no resolution! */ if ( npk == 0 ) return 0.0; - rns = malloc(npk*sizeof(double)); + rns = cfmalloc(npk*sizeof(double)); if ( rns == NULL ) return -1.0; /* Get resolution values for all peaks */ @@ -771,7 +771,7 @@ double estimate_peak_resolution(ImageFeatureList *peaks, double lambda, if ( ncut < 2 ) ncut = 0; max_res = rns[(npk-1)-ncut]; - free(rns); + cffree(rns); return max_res; } diff --git a/libcrystfel/src/predict-refine.c b/libcrystfel/src/predict-refine.c index 24045ddb..4cd0e54e 100644 --- a/libcrystfel/src/predict-refine.c +++ b/libcrystfel/src/predict-refine.c @@ -558,14 +558,14 @@ int refine_radius(Crystal *cr, struct image *image) RefList *reflist; /* Maximum possible size */ - rps = malloc(image_feature_count(image->features) - * sizeof(struct reflpeak)); + rps = cfmalloc(image_feature_count(image->features) + * sizeof(struct reflpeak)); if ( rps == NULL ) return 1; reflist = reflist_new(); n_acc = pair_peaks(image, cr, reflist, rps); if ( n_acc < 3 ) { - free(rps); + cffree(rps); reflist_free(reflist); return 1; } @@ -579,7 +579,7 @@ int refine_radius(Crystal *cr, struct image *image) crystal_set_profile_radius(cr, fabs(get_exerr(rps[n].refl))); reflist_free(reflist); - free(rps); + cffree(rps); return 0; } @@ -784,7 +784,7 @@ static double pred_residual(struct reflpeak *rps, int n, struct detgeom *det, /* NB Only for use when the list of reflpeaks was created without a RefList. - * If a RefList was used, then reflist_free the list then just free() the rps */ + * If a RefList was used, then reflist_free the list then just cffree() the rps */ static void free_rps_noreflist(struct reflpeak *rps, int n) { int i; @@ -792,7 +792,7 @@ static void free_rps_noreflist(struct reflpeak *rps, int n) for ( i=0; i<n; i++ ) { reflection_free(rps[i].refl); } - free(rps); + cffree(rps); } @@ -809,14 +809,14 @@ int refine_prediction(struct image *image, Crystal *cr, double total_shifts[12]; double res_r, res_fs, res_ss, res_overall; - rps = malloc(image_feature_count(image->features) - * sizeof(struct reflpeak)); + rps = cfmalloc(image_feature_count(image->features) + * sizeof(struct reflpeak)); if ( rps == NULL ) return 1; reflist = reflist_new(); n = pair_peaks(image, cr, reflist, rps); if ( n < 10 ) { - free(rps); + cffree(rps); reflist_free(reflist); return 1; } @@ -832,7 +832,7 @@ int refine_prediction(struct image *image, Crystal *cr, } if ( max_I <= 0.0 ) { ERROR("All peaks negative?\n"); - free(rps); + cffree(rps); crystal_set_reflections(cr, NULL); return 1; } @@ -888,7 +888,7 @@ int refine_prediction(struct image *image, Crystal *cr, for ( i=0; i<image->detgeom->n_panels; i++ ) { gsl_matrix_free(Minvs[i]); } - free(Minvs); + cffree(Minvs); crystal_set_reflections(cr, NULL); reflist_free(reflist); diff --git a/libcrystfel/src/profile.c b/libcrystfel/src/profile.c index ac76b8fa..5ca18f17 100644 --- a/libcrystfel/src/profile.c +++ b/libcrystfel/src/profile.c @@ -36,6 +36,7 @@ #include <unistd.h> #include "profile.h" +#include "utils.h" #ifndef CLOCK_MONOTONIC_RAW #define CLOCK_MONOTONIC_RAW (CLOCK_MONOTONIC) @@ -70,12 +71,12 @@ static struct _profile_block *start_profile_block(const char *name) { struct _profile_block *b; - b = malloc(sizeof(struct _profile_block)); + b = cfmalloc(sizeof(struct _profile_block)); if ( b == NULL ) return NULL; - b->name = strdup(name); + b->name = cfstrdup(name); if ( b->name == NULL ) { - free(b); + cffree(b); return NULL; } b->n_children = 0; @@ -116,7 +117,7 @@ void profile_init() } if ( pd == NULL ) { - pd = malloc(sizeof(struct _profiledata)); + pd = cfmalloc(sizeof(struct _profiledata)); if ( pd == NULL ) return; } @@ -137,7 +138,7 @@ static char *format_profile_block(struct _profile_block *b) char **subbufs; char *full_buf; - subbufs = malloc(b->n_children * sizeof(char *)); + subbufs = cfmalloc(b->n_children * sizeof(char *)); if ( subbufs == NULL ) return NULL; total_len = 32 + strlen(b->name); @@ -147,16 +148,16 @@ static char *format_profile_block(struct _profile_block *b) total_len += 1 + strlen(subbufs[i]); } - full_buf = malloc(total_len); + full_buf = cfmalloc(total_len); snprintf(full_buf, 32, "(%s %.3f", b->name, b->total_time); for ( i=0; i<b->n_children; i++ ) { strcat(full_buf, " "); strcat(full_buf, subbufs[i]); - free(subbufs[i]); + cffree(subbufs[i]); } strcat(full_buf, ")"); - free(subbufs); + cffree(subbufs); return full_buf; } @@ -168,9 +169,9 @@ static void free_profile_block(struct _profile_block *b) for ( i=0; i<b->n_children; i++ ) { free_profile_block(b->children[i]); } - free(b->children); - free(b->name); - free(b); + cffree(b->children); + cffree(b->name); + cffree(b); } @@ -195,12 +196,12 @@ void profile_print_and_reset(int worker_id) stop_profile_block(pd->root); buf = format_profile_block(pd->root); - buf2 = malloc(8+strlen(buf)); + buf2 = cfmalloc(8+strlen(buf)); size_t len = 8+strlen(buf); snprintf(buf2, len, "%i %s\n", worker_id, buf); write(STDOUT_FILENO, buf2, strlen(buf2)); - free(buf); - free(buf2); + cffree(buf); + cffree(buf2); free_profile_block(pd->root); pd->root = start_profile_block("root"); @@ -218,7 +219,7 @@ void profile_start(const char *name) if ( pd->current->n_children >= pd->current->max_children ) { struct _profile_block **nblock; int nmax = pd->current->n_children + 64; - nblock = realloc(pd->current->children, nmax*sizeof(struct _profile_block *)); + nblock = cfrealloc(pd->current->children, nmax*sizeof(struct _profile_block *)); if ( nblock == NULL ) { fprintf(stderr, "Failed to allocate profiling record. " "Try again without --profile.\n"); diff --git a/libcrystfel/src/rational.c b/libcrystfel/src/rational.c index 800decf5..88294745 100644 --- a/libcrystfel/src/rational.c +++ b/libcrystfel/src/rational.c @@ -198,7 +198,7 @@ Rational rtnl_abs(Rational a) */ char *rtnl_format(Rational rt) { - char *v = malloc(32); + char *v = cfmalloc(32); if ( v == NULL ) return NULL; if ( rt.den == 1 ) { snprintf(v, 31, "%lli", rt.num); @@ -217,7 +217,7 @@ Rational *rtnl_list(signed int num_min, signed int num_max, Rational *list; int n = 0; - list = malloc((1+num_max-num_min)*(1+den_max-den_min)*sizeof(Rational)); + list = cfmalloc((1+num_max-num_min)*(1+den_max-den_min)*sizeof(Rational)); if ( list == NULL ) return NULL; for ( num=num_min; num<=num_max; num++ ) { @@ -263,12 +263,12 @@ RationalMatrix *rtnl_mtx_new(unsigned int rows, unsigned int cols) RationalMatrix *m; int i; - m = malloc(sizeof(RationalMatrix)); + m = cfmalloc(sizeof(RationalMatrix)); if ( m == NULL ) return NULL; - m->v = calloc(rows*cols, sizeof(Rational)); + m->v = cfcalloc(rows*cols, sizeof(Rational)); if ( m->v == NULL ) { - free(m); + cffree(m); return NULL; } @@ -372,8 +372,8 @@ IntegerMatrix *intmat_from_rtnl_mtx(const RationalMatrix *m) void rtnl_mtx_free(RationalMatrix *mtx) { if ( mtx == NULL ) return; - free(mtx->v); - free(mtx); + cffree(mtx->v); + cffree(mtx); } @@ -412,7 +412,7 @@ int transform_fractional_coords_rtnl(const RationalMatrix *P, cm = rtnl_mtx_copy(P); if ( cm == NULL ) return 1; - vec = malloc(cm->rows*sizeof(Rational)); + vec = cfmalloc(cm->rows*sizeof(Rational)); if ( vec == NULL ) return 1; for ( h=0; h<cm->rows; h++ ) vec[h] = ivec[h]; @@ -489,7 +489,7 @@ int transform_fractional_coords_rtnl(const RationalMatrix *P, ans[i] = rtnl_div(sum, rtnl_mtx_get(cm, i, i)); } - free(vec); + cffree(vec); rtnl_mtx_free(cm); return 0; @@ -517,7 +517,7 @@ void rtnl_mtx_print(const RationalMatrix *m) for ( j=0; j<m->cols; j++ ) { char *v = rtnl_format(rtnl_mtx_get(m, i, j)); fprintf(stderr, "%4s ", v); - free(v); + cffree(v); } fprintf(stderr, "]\n"); } diff --git a/libcrystfel/src/reflist-utils.c b/libcrystfel/src/reflist-utils.c index 66a4996c..14e99d01 100644 --- a/libcrystfel/src/reflist-utils.c +++ b/libcrystfel/src/reflist-utils.c @@ -399,7 +399,7 @@ static RefList *read_reflections_from_file(FILE *fh, char **sym) if ( strncmp(line, "Symmetry: ", 10) != 0 ) return NULL; if ( sym != NULL ) { - *sym = strdup(line+10); + *sym = cfstrdup(line+10); } /* Read (and ignore) the header */ @@ -780,9 +780,9 @@ void free_contribs(RefList *list) { struct reflection_contributions *c; c = get_contributions(refl); - free(c->contribs); - free(c->contrib_crystals); - free(c); + cffree(c->contribs); + cffree(c->contrib_crystals); + cffree(c); } } @@ -793,13 +793,13 @@ static char *full_command_line(int argc, char *argv[]) size_t len = 1; char *cl; - if ( argc == 0 ) return strdup(""); + if ( argc == 0 ) return cfstrdup(""); for ( i=0; i<argc; i++ ) { len += strlen(argv[i]) + 1; } - cl = malloc(len); - if ( cl == NULL ) return strdup(""); + cl = cfmalloc(len); + if ( cl == NULL ) return cfstrdup(""); cl[0] = '\0'; for ( i=0; i<argc; i++ ) { @@ -822,7 +822,7 @@ void reflist_add_command_and_version(RefList *list, int argc, char *argv[]) tmp = full_command_line(argc, argv); reflist_add_notes(list, tmp); - free(tmp); + cffree(tmp); } diff --git a/libcrystfel/src/reflist.c b/libcrystfel/src/reflist.c index 71eda6b2..9ad41c5e 100644 --- a/libcrystfel/src/reflist.c +++ b/libcrystfel/src/reflist.c @@ -125,7 +125,7 @@ static Reflection *new_node(unsigned int serial) { Reflection *new; - new = calloc(1, sizeof(struct _reflection)); + new = cfcalloc(1, sizeof(struct _reflection)); if ( new == NULL ) return NULL; new->in_list = 0; new->serial = serial; @@ -149,7 +149,7 @@ RefList *reflist_new() { RefList *new; - new = malloc(sizeof(struct _reflist)); + new = cfmalloc(sizeof(struct _reflist)); if ( new == NULL ) return NULL; new->head = NULL; @@ -184,7 +184,7 @@ Reflection *reflection_new(signed int h, signed int k, signed int l) void reflection_free(Reflection *refl) { pthread_mutex_destroy(&refl->lock); - free(refl); + cffree(refl); } @@ -212,8 +212,8 @@ void reflist_free(RefList *list) if ( list->head != NULL ) { recursive_free(list->head); } /* else empty list */ - if ( list->notes != NULL ) free(list->notes); - free(list); + if ( list->notes != NULL ) cffree(list->notes); + cffree(list); } @@ -994,9 +994,9 @@ Reflection *first_refl(RefList *list, RefListIterator **piter) Reflection *refl; RefListIterator *iter; - iter = malloc(sizeof(struct _reflistiterator)); + iter = cfmalloc(sizeof(struct _reflistiterator)); iter->stack_size = 32; - iter->stack = malloc(iter->stack_size*sizeof(Reflection *)); + iter->stack = cfmalloc(iter->stack_size*sizeof(Reflection *)); iter->stack_ptr = 0; iter->is_const = 0; *piter = iter; @@ -1011,7 +1011,7 @@ Reflection *first_refl(RefList *list, RefListIterator **piter) iter->stack[iter->stack_ptr++] = refl; if ( iter->stack_ptr == iter->stack_size ) { iter->stack_size += 32; - iter->stack = realloc(iter->stack, + iter->stack = cfrealloc(iter->stack, iter->stack_size*sizeof(Reflection *)); } refl = refl->child[0]; @@ -1019,8 +1019,8 @@ Reflection *first_refl(RefList *list, RefListIterator **piter) } if ( iter->stack_ptr == 0 ) { - free(iter->stack); - free(iter); + cffree(iter->stack); + cffree(iter); return NULL; } @@ -1047,9 +1047,9 @@ const Reflection *first_refl_const(const RefList *list, RefListIterator **piter) const Reflection *refl; RefListIterator *iter; - iter = malloc(sizeof(struct _reflistiterator)); + iter = cfmalloc(sizeof(struct _reflistiterator)); iter->stack_size = 32; - iter->stack_const = malloc(iter->stack_size*sizeof(Reflection *)); + iter->stack_const = cfmalloc(iter->stack_size*sizeof(Reflection *)); iter->stack_ptr = 0; iter->is_const = 1; *piter = iter; @@ -1064,7 +1064,7 @@ const Reflection *first_refl_const(const RefList *list, RefListIterator **piter) iter->stack_const[iter->stack_ptr++] = refl; if ( iter->stack_ptr == iter->stack_size ) { iter->stack_size += 32; - iter->stack_const = realloc(iter->stack_const, + iter->stack_const = cfrealloc(iter->stack_const, iter->stack_size*sizeof(Reflection *)); } refl = refl->child[0]; @@ -1072,8 +1072,8 @@ const Reflection *first_refl_const(const RefList *list, RefListIterator **piter) } if ( iter->stack_ptr == 0 ) { - free(iter->stack_const); - free(iter); + cffree(iter->stack_const); + cffree(iter); return NULL; } @@ -1119,7 +1119,7 @@ Reflection *next_refl(Reflection *refl, RefListIterator *iter) iter->stack[iter->stack_ptr++] = refl; if ( iter->stack_ptr == iter->stack_size ) { iter->stack_size += 32; - iter->stack = realloc(iter->stack, + iter->stack = cfrealloc(iter->stack, iter->stack_size*sizeof(Reflection *)); } refl = refl->child[0]; @@ -1127,8 +1127,8 @@ Reflection *next_refl(Reflection *refl, RefListIterator *iter) } if ( iter->stack_ptr == 0 ) { - free(iter->stack); - free(iter); + cffree(iter->stack); + cffree(iter); return NULL; } @@ -1172,7 +1172,7 @@ const Reflection *next_refl_const(const Reflection *refl, RefListIterator *iter) iter->stack_const[iter->stack_ptr++] = refl; if ( iter->stack_ptr == iter->stack_size ) { iter->stack_size += 32; - iter->stack_const = realloc(iter->stack_const, + iter->stack_const = cfrealloc(iter->stack_const, iter->stack_size*sizeof(Reflection *)); } refl = refl->child[0]; @@ -1277,8 +1277,8 @@ void unlock_reflection(Reflection *refl) static void reflist_set_notes(RefList *reflist, const char *notes) { - free(reflist->notes); /* free(NULL) is OK */ - reflist->notes = strdup(notes); + cffree(reflist->notes); /* free(NULL) is OK */ + reflist->notes = cfstrdup(notes); } @@ -1315,7 +1315,7 @@ void reflist_add_notes(RefList *reflist, const char *notes_add) } len = strlen(notes_add) + strlen(reflist->notes) + 2; - nnotes = malloc(len); + nnotes = cfmalloc(len); if ( nnotes == NULL ) { ERROR("Failed to add notes to crystal.\n"); return; @@ -1324,6 +1324,6 @@ void reflist_add_notes(RefList *reflist, const char *notes_add) strcpy(nnotes, reflist->notes); strcat(nnotes, "\n"); strcat(nnotes, notes_add); - free(reflist->notes); + cffree(reflist->notes); reflist->notes = nnotes; } diff --git a/libcrystfel/src/spectrum.c b/libcrystfel/src/spectrum.c index 5f126cf0..58b822f8 100644 --- a/libcrystfel/src/spectrum.c +++ b/libcrystfel/src/spectrum.c @@ -71,7 +71,7 @@ Spectrum *spectrum_new() { Spectrum *s; - s = malloc(sizeof(Spectrum)); + s = cfmalloc(sizeof(Spectrum)); if ( s == NULL ) return NULL; s->rep = SPEC_GAUSSIANS; @@ -95,10 +95,10 @@ Spectrum *spectrum_new() void spectrum_free(Spectrum *s) { if ( s == NULL ) return; - free(s->gaussians); - free(s->k); - free(s->pdf); - free(s); + cffree(s->gaussians); + cffree(s->k); + cffree(s->pdf); + cffree(s); } @@ -292,11 +292,11 @@ static void normalise_gaussians(struct gaussian *gauss, int n_gauss) void spectrum_set_gaussians(Spectrum *s, struct gaussian *gs, int n_gauss) { /* Free old contents (if any - may be NULL) */ - free(s->gaussians); - free(s->k); - free(s->pdf); + cffree(s->gaussians); + cffree(s->k); + cffree(s->pdf); - s->gaussians = malloc(n_gauss * sizeof(struct gaussian)); + s->gaussians = cfmalloc(n_gauss * sizeof(struct gaussian)); if ( s->gaussians == NULL ) return; memcpy(s->gaussians, gs, n_gauss*sizeof(struct gaussian)); @@ -348,17 +348,17 @@ void spectrum_set_pdf(Spectrum *s, double *kvals, double *heights, int n) int i; /* Free old contents (if any - may be NULL) */ - free(s->gaussians); - free(s->k); - free(s->pdf); + cffree(s->gaussians); + cffree(s->k); + cffree(s->pdf); - s->k = malloc(n * sizeof(double)); + s->k = cfmalloc(n * sizeof(double)); if ( s->k == NULL ) return; - s->pdf = malloc(n * sizeof(double)); + s->pdf = cfmalloc(n * sizeof(double)); if ( s->pdf == NULL ) return; - perm = malloc(n * sizeof(size_t)); + perm = cfmalloc(n * sizeof(size_t)); if ( perm == NULL ) return; gsl_sort_index(perm, kvals, 1, n); @@ -367,7 +367,7 @@ void spectrum_set_pdf(Spectrum *s, double *kvals, double *heights, int n) s->k[i] = kvals[perm[i]]; s->pdf[i] = heights[perm[i]]; } - free(perm); + cffree(perm); s->n_samples = n; s->rep = SPEC_HISTOGRAM; @@ -393,8 +393,8 @@ static int read_esrf_spectrum(FILE *fh, Spectrum *s) k = srealloc(k, max_bins*sizeof(double)); samp = srealloc(samp, max_bins*sizeof(double)); if ( (k==NULL) || (samp==NULL) ) { - free(k); - free(samp); + cffree(k); + cffree(samp); return 1; } } @@ -406,8 +406,8 @@ static int read_esrf_spectrum(FILE *fh, Spectrum *s) } spectrum_set_pdf(s, k, samp, n_bins); - free(k); - free(samp); + cffree(k); + cffree(samp); return 0; } diff --git a/libcrystfel/src/stream.c b/libcrystfel/src/stream.c index 71dd7413..edbeb7af 100644 --- a/libcrystfel/src/stream.c +++ b/libcrystfel/src/stream.c @@ -453,7 +453,7 @@ int stream_write_chunk(Stream *st, const struct image *i, fprintf(st->fh, "hit = %i\n", i->hit); indexer = indexer_str(i->indexed_by); fprintf(st->fh, "indexed_by = %s\n", indexer); - free(indexer); + cffree(indexer); if ( i->indexed_by != INDEXING_NONE ) { fprintf(st->fh, "n_indexing_tries = %i\n", i->n_indexing_tries); } @@ -715,7 +715,7 @@ static void read_crystal(Stream *st, struct image *image, /* Add crystal to the list for this image */ n = image->n_crystals+1; - crystals_new = realloc(image->crystals, n*sizeof(Crystal *)); + crystals_new = cfrealloc(image->crystals, n*sizeof(Crystal *)); if ( crystals_new == NULL ) { ERROR("Failed to expand crystal list!\n"); @@ -733,7 +733,7 @@ static void parse_header(const char *line_in, struct image *image, char *line; char *pos; - line = strdup(line_in); + line = cfstrdup(line_in); chomp(line); pos = strchr(line, ' '); @@ -816,12 +816,12 @@ struct image *stream_read_chunk(Stream *st, StreamFlags srf) chomp(line); if ( strncmp(line, "Image filename: ", 16) == 0 ) { - image->filename = strdup(line+16); + image->filename = cfstrdup(line+16); have_filename = 1; } if ( strncmp(line, "Event: ", 7) == 0 ) { - image->ev = strdup(line+7); + image->ev = cfstrdup(line+7); } if ( strncmp(line, "hdf5/", 5) == 0 ) { @@ -928,7 +928,7 @@ struct image *stream_read_chunk(Stream *st, StreamFlags srf) char *stream_audit_info(Stream *st) { if ( st->audit_info == NULL ) return NULL; - return strdup(st->audit_info); + return cfstrdup(st->audit_info); } @@ -945,7 +945,7 @@ static int read_geometry_file(Stream *st) const size_t max_geom_len = 1024*1024; char *geom; - geom = malloc(max_geom_len); + geom = cfmalloc(max_geom_len); if ( geom == NULL ) { ERROR("Failed to allocate memory for geometry file\n"); return 1; @@ -962,7 +962,7 @@ static int read_geometry_file(Stream *st) if ( rval == NULL ) { ERROR("Failed to read stream geometry file.\n"); stream_close(st); - free(geom); + cffree(geom); return 1; } @@ -975,7 +975,7 @@ static int read_geometry_file(Stream *st) if ( len > max_geom_len-1 ) { ERROR("Stream's geometry file is too long (%li > %i).\n", (long)len, (int)max_geom_len); - free(geom); + cffree(geom); return 1; } else { strcat(geom, line); @@ -994,7 +994,7 @@ static int read_headers(Stream *st) int done = 0; size_t len = 0; - st->audit_info = malloc(4096); + st->audit_info = cfmalloc(4096); if ( st->audit_info == NULL ) { ERROR("Failed to allocate memory for audit information\n"); return 1; @@ -1041,7 +1041,7 @@ Stream *stream_open_for_read(const char *filename) { Stream *st; - st = malloc(sizeof(struct _stream)); + st = cfmalloc(sizeof(struct _stream)); if ( st == NULL ) return NULL; st->old_indexers = 0; st->audit_info = NULL; @@ -1058,7 +1058,7 @@ Stream *stream_open_for_read(const char *filename) } if ( st->fh == NULL ) { - free(st); + cffree(st); return NULL; } @@ -1108,7 +1108,7 @@ Stream *stream_open_fd_for_write(int fd, const DataTemplate *dtempl) { Stream *st; - st = malloc(sizeof(struct _stream)); + st = cfmalloc(sizeof(struct _stream)); if ( st == NULL ) return NULL; st->old_indexers = 0; st->audit_info = NULL; @@ -1120,7 +1120,7 @@ Stream *stream_open_fd_for_write(int fd, const DataTemplate *dtempl) st->fh = fdopen(fd, "w"); if ( st->fh == NULL ) { - free(st); + cffree(st); return NULL; } @@ -1165,7 +1165,7 @@ Stream *stream_open_for_write(const char *filename, { Stream *st; - st = malloc(sizeof(struct _stream)); + st = cfmalloc(sizeof(struct _stream)); if ( st == NULL ) return NULL; st->old_indexers = 0; st->audit_info = NULL; @@ -1178,7 +1178,7 @@ Stream *stream_open_for_write(const char *filename, st->fh = fopen(filename, "w"); if ( st->fh == NULL ) { ERROR("Failed to open stream.\n"); - free(st); + cffree(st); return NULL; } @@ -1209,11 +1209,11 @@ int stream_get_fd(Stream *st) void stream_close(Stream *st) { if ( st == NULL ) return; - free(st->audit_info); - free(st->geometry_file); + cffree(st->audit_info); + cffree(st->geometry_file); data_template_free(st->dtempl_read); fclose(st->fh); - free(st); + cffree(st); } @@ -1338,9 +1338,9 @@ struct _streamindex void stream_index_free(StreamIndex *index) { if ( index == NULL ) return; - free(index->keys); - free(index->ptrs); - free(index); + cffree(index->keys); + cffree(index->ptrs); + cffree(index); } @@ -1351,7 +1351,7 @@ static char *make_key(const char *filename, if ( ev == NULL ) ev = "//"; - key = malloc(strlen(filename)+strlen(ev)+2); + key = cfmalloc(strlen(filename)+strlen(ev)+2); if ( key == NULL ) return NULL; strcpy(key, filename); @@ -1398,14 +1398,14 @@ static void add_index_record(StreamIndex *index, char **new_keys; long int *new_ptrs; - new_keys = realloc(index->keys, - new_max_keys*sizeof(char *)); + new_keys = cfrealloc(index->keys, + new_max_keys*sizeof(char *)); if ( new_keys == NULL ) return; - new_ptrs = realloc(index->ptrs, - new_max_keys*sizeof(long int)); + new_ptrs = cfrealloc(index->ptrs, + new_max_keys*sizeof(long int)); if ( new_ptrs == NULL ) { - free(new_keys); + cffree(new_keys); return; } @@ -1436,7 +1436,7 @@ StreamIndex *stream_make_index(const char *filename) fh = fopen(filename, "r"); if ( fh == NULL ) return NULL; - index = malloc(sizeof(StreamIndex)); + index = cfmalloc(sizeof(StreamIndex)); if ( index == NULL ) { fclose(fh); return NULL; @@ -1467,11 +1467,11 @@ StreamIndex *stream_make_index(const char *filename) } if ( strncmp(line, "Image filename: ", 16) == 0 ) { - last_filename = strdup(line+16); + last_filename = cfstrdup(line+16); } if ( strncmp(line, "Event: ", 7) == 0 ) { - last_ev = strdup(line+7); + last_ev = cfstrdup(line+7); } if ( strcmp(line, STREAM_CHUNK_END_MARKER) == 0 ) { @@ -1483,8 +1483,8 @@ StreamIndex *stream_make_index(const char *filename) last_filename, last_ev); } - free(last_filename); - free(last_ev); + cffree(last_filename); + cffree(last_ev); last_start_pos = 0; last_filename = NULL; last_ev = NULL; diff --git a/libcrystfel/src/symmetry.c b/libcrystfel/src/symmetry.c index 6cda54a2..7568f2a1 100644 --- a/libcrystfel/src/symmetry.c +++ b/libcrystfel/src/symmetry.c @@ -66,7 +66,7 @@ struct _symopmask static void alloc_ops(SymOpList *ops) { - ops->ops = realloc(ops->ops, ops->max_ops*sizeof(IntegerMatrix *)); + ops->ops = cfrealloc(ops->ops, ops->max_ops*sizeof(IntegerMatrix *)); } @@ -82,13 +82,13 @@ SymOpMask *new_symopmask(const SymOpList *list) SymOpMask *m; int i; - m = malloc(sizeof(struct _symopmask)); + m = cfmalloc(sizeof(struct _symopmask)); if ( m == NULL ) return NULL; m->list = list; - m->mask = malloc(sizeof(int)*list->n_ops); + m->mask = cfmalloc(sizeof(int)*list->n_ops); if ( m->mask == NULL ) { - free(m); + cffree(m); return NULL; } @@ -104,7 +104,7 @@ SymOpMask *new_symopmask(const SymOpList *list) static SymOpList *new_symoplist() { SymOpList *new; - new = malloc(sizeof(SymOpList)); + new = cfmalloc(sizeof(SymOpList)); if ( new == NULL ) return NULL; new->max_ops = 16; new->n_ops = 0; @@ -129,9 +129,9 @@ void free_symoplist(SymOpList *ops) for ( i=0; i<ops->n_ops; i++ ) { intmat_free(ops->ops[i]); } - if ( ops->ops != NULL ) free(ops->ops); - if ( ops->name != NULL ) free(ops->name); - free(ops); + if ( ops->ops != NULL ) cffree(ops->ops); + if ( ops->name != NULL ) cffree(ops->name); + cffree(ops); } /** @@ -142,8 +142,8 @@ void free_symoplist(SymOpList *ops) void free_symopmask(SymOpMask *m) { if ( m == NULL ) return; - free(m->mask); - free(m); + cffree(m->mask); + cffree(m); } @@ -186,9 +186,9 @@ static void add_symop_v(SymOpList *ops, for ( i=0; i<3; i++ ) intmat_set(m, i, 1, k[i]); for ( i=0; i<3; i++ ) intmat_set(m, i, 2, l[i]); - free(h); - free(k); - free(l); + cffree(h); + cffree(k); + cffree(l); add_symop(ops, m); } @@ -248,7 +248,7 @@ IntegerMatrix *get_symop(const SymOpList *ops, const SymOpMask *m, int idx) static signed int *v(signed int h, signed int k, signed int i, signed int l) { - signed int *vec = malloc(3*sizeof(signed int)); + signed int *vec = cfmalloc(3*sizeof(signed int)); if ( vec == NULL ) return NULL; /* Convert back to 3-index form now */ vec[0] = h-i; vec[1] = k-i; vec[2] = l; @@ -411,7 +411,7 @@ static SymOpList *make_1bar() { SymOpList *new = new_symoplist(); add_symop_v(new, v(-1,0,0,0), v(0,-1,0,0), v(0,0,0,-1)); /* -I */ - new->name = strdup("-1"); + new->name = cfstrdup("-1"); expand_ops(new); return new; } @@ -420,7 +420,7 @@ static SymOpList *make_1bar() static SymOpList *make_1() { SymOpList *new = new_symoplist(); - new->name = strdup("1"); + new->name = cfstrdup("1"); expand_ops(new); return new; } @@ -433,7 +433,7 @@ static SymOpList *make_2m() SymOpList *new = new_symoplist(); add_symop_v(new, v(-1,0,0,0), v(0,-1,0,0), v(0,0,0,1)); /* 2 // l */ add_symop_v(new, v(1,0,0,0), v(0,1,0,0), v(0,0,0,-1)); /* m -| l */ - new->name = strdup("2/m"); + new->name = cfstrdup("2/m"); expand_ops(new); return new; } @@ -443,7 +443,7 @@ static SymOpList *make_2() { SymOpList *new = new_symoplist(); add_symop_v(new, v(-1,0,0,0), v(0,-1,0,0), v(0,0,0,1)); /* 2 // l */ - new->name = strdup("2"); + new->name = cfstrdup("2"); expand_ops(new); return new; } @@ -453,7 +453,7 @@ static SymOpList *make_m() { SymOpList *new = new_symoplist(); add_symop_v(new, v(1,0,0,0), v(0,1,0,0), v(0,0,0,-1)); /* m -| l */ - new->name = strdup("m"); + new->name = cfstrdup("m"); expand_ops(new); return new; } @@ -467,7 +467,7 @@ static SymOpList *make_mmm() add_symop_v(new, v(-1,0,0,0), v(0,-1,0,0), v(0,0,0,1)); /* 2 // l */ add_symop_v(new, v(-1,0,0,0), v(0,1,0,0), v(0,0,0,-1)); /* 2 // k */ add_symop_v(new, v(1,0,0,0), v(0,-1,0,0), v(0,0,0,1)); /* m -| k */ - new->name = strdup("mmm"); + new->name = cfstrdup("mmm"); expand_ops(new); return new; } @@ -478,7 +478,7 @@ static SymOpList *make_222() SymOpList *new = new_symoplist(); add_symop_v(new, v(-1,0,0,0), v(0,-1,0,0), v(0,0,0,1)); /* 2 // l */ add_symop_v(new, v(-1,0,0,0), v(0,1,0,0), v(0,0,0,-1)); /* 2 // k */ - new->name = strdup("222"); + new->name = cfstrdup("222"); expand_ops(new); return new; } @@ -489,7 +489,7 @@ static SymOpList *make_mm2() SymOpList *new = new_symoplist(); add_symop_v(new, v(-1,0,0,0), v(0,-1,0,0), v(0,0,0,1)); /* 2 // l */ add_symop_v(new, v(1,0,0,0), v(0,-1,0,0), v(0,0,0,1)); /* m -| k */ - new->name = strdup("mm2"); + new->name = cfstrdup("mm2"); expand_ops(new); return new; } @@ -502,7 +502,7 @@ static SymOpList *make_4m() SymOpList *new = new_symoplist(); add_symop_v(new, v(0,-1,0,0), v(1,0,0,0), v(0,0,0,1)); /* 4 // l */ add_symop_v(new, v(1,0,0,0), v(0,1,0,0), v(0,0,0,-1)); /* m -| l */ - new->name = strdup("4/m"); + new->name = cfstrdup("4/m"); expand_ops(new); return new; } @@ -512,7 +512,7 @@ static SymOpList *make_4() { SymOpList *new = new_symoplist(); add_symop_v(new, v(0,-1,0,0), v(1,0,0,0), v(0,0,0,1)); /* 4 // l */ - new->name = strdup("4"); + new->name = cfstrdup("4"); expand_ops(new); return new; } @@ -523,7 +523,7 @@ static SymOpList *make_4mm() SymOpList *new = new_symoplist(); add_symop_v(new, v(0,-1,0,0), v(1,0,0,0), v(0,0,0,1)); /* 4 // l */ add_symop_v(new, v(-1,0,0,0), v(0,1,0,0), v(0,0,0,1)); /* m -| l */ - new->name = strdup("4mm"); + new->name = cfstrdup("4mm"); expand_ops(new); return new; } @@ -534,7 +534,7 @@ static SymOpList *make_422() SymOpList *new = new_symoplist(); add_symop_v(new, v(0,-1,0,0), v(1,0,0,0), v(0,0,0,1)); /* 4 // l */ add_symop_v(new, v(-1,0,0,0), v(0,1,0,0), v(0,0,0,-1)); /* 2 // k */ - new->name = strdup("422"); + new->name = cfstrdup("422"); expand_ops(new); return new; } @@ -544,7 +544,7 @@ static SymOpList *make_4bar() { SymOpList *new = new_symoplist(); add_symop_v(new, v(0,1,0,0), v(-1,0,0,0), v(0,0,0,-1)); /* -4 // l */ - new->name = strdup("-4"); + new->name = cfstrdup("-4"); expand_ops(new); return new; } @@ -555,7 +555,7 @@ static SymOpList *make_4bar2m() SymOpList *new = new_symoplist(); add_symop_v(new, v(0,1,0,0), v(-1,0,0,0), v(0,0,0,-1)); /* -4 // l */ add_symop_v(new, v(-1,0,0,0), v(0,1,0,0), v(0,0,0,-1)); /* 2 // k */ - new->name = strdup("-42m"); + new->name = cfstrdup("-42m"); expand_ops(new); return new; } @@ -566,7 +566,7 @@ static SymOpList *make_4barm2() SymOpList *new = new_symoplist(); add_symop_v(new, v(0,1,0,0), v(-1,0,0,0), v(0,0,0,-1)); /* -4 // l */ add_symop_v(new, v(0,1,0,0), v(1,0,0,0), v(0,0,0,-1)); /* 2 // h+k */ - new->name = strdup("-4m2"); + new->name = cfstrdup("-4m2"); expand_ops(new); return new; } @@ -578,7 +578,7 @@ static SymOpList *make_4mmm() add_symop_v(new, v(0,-1,0,0), v(1,0,0,0), v(0,0,0,1)); /* 4 // l */ add_symop_v(new, v(-1,0,0,0), v(0,1,0,0), v(0,0,0,1)); /* m -| k */ add_symop_v(new, v(1,0,0,0), v(0,1,0,0), v(0,0,0,-1)); /* m -| l */ - new->name = strdup("4/mmm"); + new->name = cfstrdup("4/mmm"); expand_ops(new); return new; } @@ -590,7 +590,7 @@ static SymOpList *make_3_R() { SymOpList *new = new_symoplist(); add_symop_v(new, v(0,0,0,1), v(1,0,0,0), v(0,1,0,0)); /* 3 // h+k+l */ - new->name = strdup("3_R"); + new->name = cfstrdup("3_R"); expand_ops(new); return new; } @@ -601,7 +601,7 @@ static SymOpList *make_3bar_R() SymOpList *new = new_symoplist(); add_symop_v(new, v(0,0,0,1), v(1,0,0,0), v(0,1,0,0)); /* -3 // h+k+l */ add_symop_v(new, v(-1,0,0,0), v(0,-1,0,0), v(0,0,0,-1)); /* -I */ - new->name = strdup("-3_R"); + new->name = cfstrdup("-3_R"); expand_ops(new); return new; } @@ -612,7 +612,7 @@ static SymOpList *make_32_R() SymOpList *new = new_symoplist(); add_symop_v(new, v(0,0,0,1), v(1,0,0,0), v(0,1,0,0)); /* 3 // h+k+l */ add_symop_v(new, v(0,-1,0,0), v(-1,0,0,0), v(0,0,0,-1)); /* 2 -| 3 */ - new->name = strdup("32_R"); + new->name = cfstrdup("32_R"); expand_ops(new); return new; } @@ -623,7 +623,7 @@ static SymOpList *make_3m_R() SymOpList *new = new_symoplist(); add_symop_v(new, v(0,0,0,1), v(1,0,0,0), v(0,1,0,0)); /* 3 // h+k+l */ add_symop_v(new, v(0,1,0,0), v(1,0,0,0), v(0,0,0,1)); /* m */ - new->name = strdup("3m_R"); + new->name = cfstrdup("3m_R"); expand_ops(new); return new; } @@ -635,7 +635,7 @@ static SymOpList *make_3barm_R() add_symop_v(new, v(0,0,0,1), v(1,0,0,0), v(0,1,0,0)); /* -3 // h+k+l */ add_symop_v(new, v(-1,0,0,0), v(0,-1,0,0), v(0,0,0,-1)); /* -I */ add_symop_v(new, v(0,1,0,0), v(1,0,0,0), v(0,0,0,1)); /* m */ - new->name = strdup("-3m_R"); + new->name = cfstrdup("-3m_R"); expand_ops(new); return new; } @@ -647,7 +647,7 @@ static SymOpList *make_3_H() { SymOpList *new = new_symoplist(); add_symop_v(new, v(0,0,1,0), v(1,0,0,0), v(0,0,0,1)); /* 3 // l */ - new->name = strdup("3_H"); + new->name = cfstrdup("3_H"); expand_ops(new); return new; } @@ -658,7 +658,7 @@ static SymOpList *make_3bar_H() SymOpList *new = new_symoplist(); add_symop_v(new, v(0,0,1,0), v(1,0,0,0), v(0,0,0,1)); /* 3 // l */ add_symop_v(new, v(-1,0,0,0), v(0,-1,0,0), v(0,0,0,-1)); /* -I */ - new->name = strdup("-3_H"); + new->name = cfstrdup("-3_H"); expand_ops(new); return new; } @@ -669,7 +669,7 @@ static SymOpList *make_321_H() SymOpList *new = new_symoplist(); add_symop_v(new, v(0,0,1,0), v(1,0,0,0), v(0,0,0,1)); /* 3 // l */ add_symop_v(new, v(0,1,0,0), v(1,0,0,0), v(0,0,0,-1)); /* 2 // h */ - new->name = strdup("321_H"); + new->name = cfstrdup("321_H"); expand_ops(new); return new; } @@ -680,7 +680,7 @@ static SymOpList *make_312_H() SymOpList *new = new_symoplist(); add_symop_v(new, v(0,0,1,0), v(1,0,0,0), v(0,0,0,1)); /* 3 // l */ add_symop_v(new, v(0,-1,0,0), v(-1,0,0,0), v(0,0,0,-1)); /* 2 // h+k */ - new->name = strdup("312_H"); + new->name = cfstrdup("312_H"); expand_ops(new); return new; } @@ -691,7 +691,7 @@ static SymOpList *make_3m1_H() SymOpList *new = new_symoplist(); add_symop_v(new, v(0,0,1,0), v(1,0,0,0), v(0,0,0,1)); /* 3 // l */ add_symop_v(new, v(0,-1,0,0), v(-1,0,0,0), v(0,0,0,1)); /* m -| i */ - new->name = strdup("3m1_H"); + new->name = cfstrdup("3m1_H"); expand_ops(new); return new; } @@ -702,7 +702,7 @@ static SymOpList *make_31m_H() SymOpList *new = new_symoplist(); add_symop_v(new, v(0,0,1,0), v(1,0,0,0), v(0,0,0,1)); /* 3 // l */ add_symop_v(new, v(0,1,0,0), v(1,0,0,0), v(0,0,0,1)); /* m -| (k+i) */ - new->name = strdup("31m_H"); + new->name = cfstrdup("31m_H"); expand_ops(new); return new; } @@ -714,7 +714,7 @@ static SymOpList *make_3barm1_H() add_symop_v(new, v(0,0,1,0), v(1,0,0,0), v(0,0,0,1)); /* 3 // l */ add_symop_v(new, v(-1,0,0,0), v(0,-1,0,0), v(0,0,0,-1)); /* -I */ add_symop_v(new, v(0,1,0,0), v(1,0,0,0), v(0,0,0,-1)); /* 2 // h */ - new->name = strdup("-3m1_H"); + new->name = cfstrdup("-3m1_H"); expand_ops(new); return new; } @@ -726,7 +726,7 @@ static SymOpList *make_3bar1m_H() add_symop_v(new, v(0,0,1,0), v(1,0,0,0), v(0,0,0,1)); /* 3 // l */ add_symop_v(new, v(-1,0,0,0), v(0,-1,0,0), v(0,0,0,-1)); /* -I */ add_symop_v(new, v(0,-1,0,0), v(-1,0,0,0), v(0,0,0,-1)); /* 2 // h+k */ - new->name = strdup("-31m_H"); + new->name = cfstrdup("-31m_H"); expand_ops(new); return new; } @@ -738,7 +738,7 @@ static SymOpList *make_6() { SymOpList *new = new_symoplist(); add_symop_v(new, v(0,0,-1,0), v(-1,0,0,0), v(0,0,0,1)); /* 6 // l */ - new->name = strdup("6"); + new->name = cfstrdup("6"); expand_ops(new); return new; } @@ -748,7 +748,7 @@ static SymOpList *make_6bar() { SymOpList *new = new_symoplist(); add_symop_v(new, v(0,0,1,0), v(1,0,0,0), v(0,0,0,-1)); /* -6 // l */ - new->name = strdup("-6"); + new->name = cfstrdup("-6"); expand_ops(new); return new; } @@ -759,7 +759,7 @@ static SymOpList *make_6m() SymOpList *new = new_symoplist(); add_symop_v(new, v(0,0,-1,0), v(-1,0,0,0), v(0,0,0,1)); /* 6 // l */ add_symop_v(new, v(1,0,0,0), v(0,1,0,0), v(0,0,0,-1)); /* m -| l */ - new->name = strdup("6/m"); + new->name = cfstrdup("6/m"); expand_ops(new); return new; } @@ -770,7 +770,7 @@ static SymOpList *make_622() SymOpList *new = new_symoplist(); add_symop_v(new, v(0,0,-1,0), v(-1,0,0,0), v(0,0,0,1)); /* 6 // l */ add_symop_v(new, v(0,1,0,0), v(1,0,0,0), v(0,0,0,-1)); /* 2 // h */ - new->name = strdup("622"); + new->name = cfstrdup("622"); expand_ops(new); return new; } @@ -781,7 +781,7 @@ static SymOpList *make_6mm() SymOpList *new = new_symoplist(); add_symop_v(new, v(0,0,-1,0), v(-1,0,0,0), v(0,0,0,1)); /* 6 // l */ add_symop_v(new, v(0,-1,0,0), v(-1,0,0,0), v(0,0,0,1)); /* m -| i */ - new->name = strdup("6mm"); + new->name = cfstrdup("6mm"); expand_ops(new); return new; } @@ -792,7 +792,7 @@ static SymOpList *make_6barm2() SymOpList *new = new_symoplist(); add_symop_v(new, v(0,0,1,0), v(1,0,0,0), v(0,0,0,-1)); /* -6 // l */ add_symop_v(new, v(0,-1,0,0), v(-1,0,0,0), v(0,0,0,1)); /* m -| i */ - new->name = strdup("-6m2"); + new->name = cfstrdup("-6m2"); expand_ops(new); return new; } @@ -803,7 +803,7 @@ static SymOpList *make_6bar2m() SymOpList *new = new_symoplist(); add_symop_v(new, v(0,0,1,0), v(1,0,0,0), v(0,0,0,-1)); /* -6 // l */ add_symop_v(new, v(0,1,0,0), v(1,0,0,0), v(0,0,0,1)); /* m -| (k+i) */ - new->name = strdup("-62m"); + new->name = cfstrdup("-62m"); expand_ops(new); return new; } @@ -815,7 +815,7 @@ static SymOpList *make_6mmm() add_symop_v(new, v(0,0,1,0), v(1,0,0,0), v(0,0,0,-1)); /* -6 // l */ add_symop_v(new, v(0,-1,0,0), v(-1,0,0,0), v(0,0,0,1)); /* m -| i */ add_symop_v(new, v(-1,0,0,0), v(0,-1,0,0), v(0,0,0,-1)); /* -I */ - new->name = strdup("6/mmm"); + new->name = cfstrdup("6/mmm"); expand_ops(new); return new; } @@ -829,7 +829,7 @@ static SymOpList *make_23() add_symop_v(new, v(-1,0,0,0), v(0,-1,0,0), v(0,0,0,1)); /* 2 // l */ add_symop_v(new, v(-1,0,0,0), v(0,1,0,0), v(0,0,0,-1)); /* 2 // k */ add_symop_v(new, v(0,1,0,0), v(0,0,0,1), v(1,0,0,0)); /* 3 // h+k+l */ - new->name = strdup("23"); + new->name = cfstrdup("23"); expand_ops(new); return new; } @@ -842,7 +842,7 @@ static SymOpList *make_m3bar() add_symop_v(new, v(-1,0,0,0), v(0,1,0,0), v(0,0,0,-1)); /* 2 // k */ add_symop_v(new, v(0,1,0,0), v(0,0,0,1), v(1,0,0,0)); /* 3 // h+k+l */ add_symop_v(new, v(-1,0,0,0), v(0,-1,0,0), v(0,0,0,-1)); /* -I */ - new->name = strdup("m-3"); + new->name = cfstrdup("m-3"); expand_ops(new); return new; } @@ -854,7 +854,7 @@ static SymOpList *make_432() add_symop_v(new, v(0,-1,0,0), v(1,0,0,0), v(0,0,0,1)); /* 4 // l */ add_symop_v(new, v(-1,0,0,0), v(0,1,0,0), v(0,0,0,-1));/* 2 // k */ add_symop_v(new, v(0,1,0,0), v(0,0,0,1), v(1,0,0,0)); /* 3 // h+k+l */ - new->name = strdup("432"); + new->name = cfstrdup("432"); expand_ops(new); return new; } @@ -866,7 +866,7 @@ static SymOpList *make_4bar3m() add_symop_v(new, v(0,1,0,0), v(-1,0,0,0), v(0,0,0,-1)); /* -4 // l */ add_symop_v(new, v(-1,0,0,0), v(0,1,0,0), v(0,0,0,-1)); /* 2 // k */ add_symop_v(new, v(0,1,0,0), v(0,0,0,1), v(1,0,0,0)); /* 3 // h+k+l */ - new->name = strdup("-43m"); + new->name = cfstrdup("-43m"); expand_ops(new); return new; } @@ -879,7 +879,7 @@ static SymOpList *make_m3barm() add_symop_v(new, v(-1,0,0,0), v(0,1,0,0), v(0,0,0,-1));/* 2 // k */ add_symop_v(new, v(0,1,0,0), v(0,0,0,1), v(1,0,0,0)); /* 3 // h+k+l */ add_symop_v(new, v(-1,0,0,0), v(0,-1,0,0), v(0,0,0,-1)); /* -I */ - new->name = strdup("m-3m"); + new->name = cfstrdup("m-3m"); expand_ops(new); return new; } @@ -979,7 +979,7 @@ static SymOpList *getpg_arbitrary_ua(const char *sym, size_t s) return NULL; } - pg_type = strndup(sym, s-1); + pg_type = cfstrndup(sym, s-1); if ( pg_type == NULL ) { ERROR("Couldn't allocate string.\n"); return NULL; @@ -991,7 +991,7 @@ static SymOpList *getpg_arbitrary_ua(const char *sym, size_t s) pg_type); return NULL; } - free(pg_type); + cffree(pg_type); t = intmat_new(3, 3); if ( t == NULL ) return NULL; @@ -1027,14 +1027,14 @@ static SymOpList *getpg_arbitrary_ua(const char *sym, size_t s) transform_ops(pg, t); intmat_free(t); - new_name = malloc(64); + new_name = cfmalloc(64); if ( new_name == NULL ) { ERROR("Couldn't allocate space for PG name\n"); return NULL; } snprintf(new_name, 64, "%s_ua%c", pg->name, ua); - free(pg->name); + cffree(pg->name); pg->name = new_name; return pg; @@ -1115,7 +1115,7 @@ static void do_op(const IntegerMatrix *op, assert(ans != NULL); *he = ans[0]; *ke = ans[1]; *le = ans[2]; - free(ans); + cffree(ans); } @@ -1175,9 +1175,9 @@ void special_position(const SymOpList *ops, SymOpMask *m, assert(m->list == ops); n = num_equivs(ops, NULL); - htest = malloc(n*sizeof(signed int)); - ktest = malloc(n*sizeof(signed int)); - ltest = malloc(n*sizeof(signed int)); + htest = cfmalloc(n*sizeof(signed int)); + ktest = cfmalloc(n*sizeof(signed int)); + ltest = cfmalloc(n*sizeof(signed int)); for ( i=0; i<n; i++ ) { @@ -1202,9 +1202,9 @@ void special_position(const SymOpList *ops, SymOpMask *m, } - free(htest); - free(ktest); - free(ltest); + cffree(htest); + cffree(ktest); + cffree(ltest); } @@ -1609,7 +1609,7 @@ SymOpList *get_ambiguities(const SymOpList *source, const SymOpList *target) free_symoplist(src_reordered); free_symoplist(tgt_reordered); - name = malloc(64); + name = cfmalloc(64); snprintf(name, 63, "%s -> %s", symmetry_name(source), symmetry_name(target)); twins->name = name; @@ -1716,7 +1716,7 @@ char *get_matrix_name(const IntegerMatrix *m, int col) int i; int printed = 0; - text = malloc(max_len+1); + text = cfmalloc(max_len+1); text[0] = '\0'; for ( i=0; i<3; i++ ) { @@ -1763,7 +1763,7 @@ static char *name_equiv(const IntegerMatrix *op) h = get_matrix_name(op, 0); k = get_matrix_name(op, 1); l = get_matrix_name(op, 2); - name = malloc(32); + name = cfmalloc(32); if ( strlen(h)+strlen(k)+strlen(l) == 3 ) { snprintf(name, 31, "%s%s%s", h, k, l); @@ -1794,7 +1794,7 @@ void describe_symmetry(const SymOpList *s) char *name = name_equiv(s->ops[i]); len = strlen(name); if ( len > max_len ) max_len = len; - free(name); + cffree(name); } if ( max_len < 8 ) max_len = 8; @@ -1810,7 +1810,7 @@ void describe_symmetry(const SymOpList *s) for ( j=0; j<m; j++ ) { STATUS(" "); } - free(name); + cffree(name); if ( (i!=0) && (i%8==0) ) STATUS("\n%15s ", ""); } @@ -1839,5 +1839,5 @@ const char *symmetry_name(const SymOpList *ops) */ void set_symmetry_name(SymOpList *ops, const char *name) { - ops->name = strdup(name); + ops->name = cfstrdup(name); } diff --git a/libcrystfel/src/thread-pool.c b/libcrystfel/src/thread-pool.c index 0951fcc6..fb17e7e4 100644 --- a/libcrystfel/src/thread-pool.c +++ b/libcrystfel/src/thread-pool.c @@ -88,11 +88,11 @@ static void *task_worker(void *pargsv) struct task_queue *q = w->tq; int *cookie_slot; - cookie_slot = malloc(sizeof(int)); + cookie_slot = cfmalloc(sizeof(int)); *cookie_slot = w->id; pthread_setspecific(status_label_key, cookie_slot); - free(w); + cffree(w); do { @@ -129,7 +129,7 @@ static void *task_worker(void *pargsv) } while ( 1 ); - free(cookie_slot); + cffree(cookie_slot); return NULL; } @@ -173,7 +173,7 @@ int run_threads(int n_threads, TPWorkFunc work, pthread_key_create(&status_label_key, NULL); - workers = malloc(n_threads * sizeof(pthread_t)); + workers = cfmalloc(n_threads * sizeof(pthread_t)); pthread_mutex_init(&q.lock, NULL); q.work = work; @@ -192,7 +192,7 @@ int run_threads(int n_threads, TPWorkFunc work, struct worker_args *w; - w = malloc(sizeof(struct worker_args)); + w = cfmalloc(sizeof(struct worker_args)); w->tq = &q; w->tqr = NULL; @@ -214,7 +214,7 @@ int run_threads(int n_threads, TPWorkFunc work, use_status_labels = 0; - free(workers); + cffree(workers); return q.n_completed; } diff --git a/libcrystfel/src/utils.c b/libcrystfel/src/utils.c index 04e028e9..7bfac487 100644 --- a/libcrystfel/src/utils.c +++ b/libcrystfel/src/utils.c @@ -436,9 +436,9 @@ char *cfstrndup(const char *s, size_t n) void *srealloc(void *arr, size_t new_size) { - void *new_arr = realloc(arr, new_size); + void *new_arr = cfrealloc(arr, new_size); if ( new_arr == NULL ) { - free(arr); + cffree(arr); return NULL; } else { return new_arr; @@ -448,7 +448,7 @@ void *srealloc(void *arr, size_t new_size) char *safe_strdup(const char *in) { if ( in == NULL ) return NULL; - return strdup(in); + return cfstrdup(in); } @@ -632,9 +632,9 @@ static int assplode_extract(char ***pbits, int n, size_t n_captured, size_t start, const char *a) { char **bits = *pbits; - bits = realloc(bits, sizeof(char *)*(n+1)); + bits = cfrealloc(bits, sizeof(char *)*(n+1)); assert(bits != NULL); - bits[n] = malloc(n_captured+1); + bits[n] = cfmalloc(n_captured+1); assert(bits[n] != NULL); memcpy(bits[n], a+start, n_captured); bits[n][n_captured] = '\0'; @@ -649,8 +649,8 @@ static int assplode_extract(char ***pbits, int n, size_t n_captured, * deliminators. * Store each segment in bits[0...n] where n is the number of segments and is * the return value. pbits = &bits - * Each segment needs to be freed with free() when finished with. - * The array of bits also needs to be freed with free() when finished with, + * Each segment needs to be freed with cffree() when finished with. + * The array of bits also needs to be freed with cffree() when finished with, * unless n=0 in which case bits==NULL */ int assplode(const char *a, const char *delims, char ***pbits, @@ -742,9 +742,9 @@ char *check_prefix(char *prefix) " with a slash. I'm going to add it for you.\n", prefix); STATUS("If this isn't what you want, run with --no-check-prefix.\n"); len = strlen(prefix)+2; - new = malloc(len); + new = cfmalloc(len); snprintf(new, len, "%s/", prefix); - free(prefix); + cffree(prefix); return new; } @@ -755,7 +755,7 @@ char *safe_basename(const char *in) char *cpy; char *res; - cpy = strdup(in); + cpy = cfstrdup(in); /* Get rid of any trailing slashes */ for ( i=strlen(cpy)-1; i>0; i-- ) { @@ -774,10 +774,10 @@ char *safe_basename(const char *in) } } - res = strdup(cpy+i); + res = cfstrdup(cpy+i); /* If we didn't find a previous slash, i==0 so res==cpy */ - free(cpy); + cffree(cpy); return res; } @@ -962,7 +962,7 @@ char *load_entire_file(const char *filename) return NULL; } - contents = malloc(statbuf.st_size+1); + contents = cfmalloc(statbuf.st_size+1); if ( contents == NULL ) { ERROR("Failed to allocate memory for file\n"); return NULL; @@ -971,14 +971,14 @@ char *load_entire_file(const char *filename) fh = fopen(filename, "r"); if ( fh == NULL ) { ERROR("Failed to open file '%s'\n", filename); - free(contents); + cffree(contents); return NULL; } if ( fread(contents, 1, statbuf.st_size, fh) != statbuf.st_size ) { ERROR("Failed to read file '%s'\n", filename); fclose(fh); - free(contents); + cffree(contents); return NULL; } contents[statbuf.st_size] = '\0'; |