From 274a5e2803eb3afe0d53b27c6078ef4495d587a0 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Wed, 17 Mar 2010 14:09:49 +0100 Subject: Fix various memory leaks and tidy a few things --- src/sfac.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'src/sfac.c') diff --git a/src/sfac.c b/src/sfac.c index 0e8b9382..81e381b3 100644 --- a/src/sfac.c +++ b/src/sfac.c @@ -323,6 +323,7 @@ struct molecule *load_molecule() if ( mol == NULL ) return NULL; mol->n_species = 0; mol->reflections = NULL; + mol->cell = NULL; fh = fopen("molecule.pdb", "r"); if ( fh == NULL ) { @@ -443,6 +444,41 @@ struct molecule *load_molecule() } +void free_molecule(struct molecule *mol) +{ + int i; + + for ( i=0; in_species; i++ ) { + free(mol->species[i]); + } + + free(mol->cell); + free(mol); +} + + +struct molecule *copy_molecule(struct molecule *orig) +{ + struct molecule *new; + int i; + + new = malloc(sizeof(*new)); + *new = *orig; + + /* Now sort out pointers */ + for ( i=0; in_species; i++ ) { + new->species[i] = malloc(sizeof(struct mol_species)); + memcpy(new->species[i], orig->species[i], + sizeof(struct mol_species)); + } + + new->cell = cell_new_from_cell(orig->cell); + new->reflections = NULL; + + return new; +} + + double complex *get_reflections(struct molecule *mol, double en) { double complex *reflections; -- cgit v1.2.3