aboutsummaryrefslogtreecommitdiff
path: root/libcrystfel/src/indexers
diff options
context:
space:
mode:
Diffstat (limited to 'libcrystfel/src/indexers')
-rw-r--r--libcrystfel/src/indexers/asdf.c68
-rw-r--r--libcrystfel/src/indexers/dirax.c31
-rw-r--r--libcrystfel/src/indexers/felix.c38
-rw-r--r--libcrystfel/src/indexers/fromfile.c20
-rw-r--r--libcrystfel/src/indexers/mosflm.c45
-rw-r--r--libcrystfel/src/indexers/pinkindexer.c8
-rw-r--r--libcrystfel/src/indexers/taketwo.c86
-rw-r--r--libcrystfel/src/indexers/xds.c4
-rw-r--r--libcrystfel/src/indexers/xgandalf.c6
9 files changed, 152 insertions, 154 deletions
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..30305b21 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 );
@@ -337,7 +337,7 @@ int fromfile_index(struct image *image, void *mpriv)
for ( i=0; i<p->n_crystals; i++ ) {
Crystal *cr;
- cr = crystal_copy_deep(p->crystals[i]);
+ cr = crystal_copy(p->crystals[i]);
image_add_crystal(image, cr);
}
@@ -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;