diff options
author | Thomas White <taw@physics.org> | 2010-03-17 14:09:49 +0100 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2010-03-17 14:09:49 +0100 |
commit | 274a5e2803eb3afe0d53b27c6078ef4495d587a0 (patch) | |
tree | a1bc21d37e94ff5450cddc148cd33227b30f94ad /src/sfac.c | |
parent | f38be837bd33dfc4d98d251b2e81d5fa555a4f5c (diff) |
Fix various memory leaks and tidy a few things
Diffstat (limited to 'src/sfac.c')
-rw-r--r-- | src/sfac.c | 36 |
1 files changed, 36 insertions, 0 deletions
@@ -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; i<mol->n_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; i<orig->n_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; |