aboutsummaryrefslogtreecommitdiff
path: root/src/cell.c
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.org.uk>2011-01-26 17:57:44 +0100
committerThomas White <taw@physics.org>2012-02-22 15:27:12 +0100
commite3a2807bedf1a1a9e25923ee9bc0db653c4c4033 (patch)
treec8bb22ff1ab2b38e37fa70d545c6bdcc0cf0e7b7 /src/cell.c
parenteb24fd94de4e5d59b691acf0b1bfd43de64d66c1 (diff)
Fix many small memory leaks
Diffstat (limited to 'src/cell.c')
-rw-r--r--src/cell.c29
1 files changed, 24 insertions, 5 deletions
diff --git a/src/cell.c b/src/cell.c
index 9fa506b0..c3a65066 100644
--- a/src/cell.c
+++ b/src/cell.c
@@ -81,6 +81,7 @@ UnitCell *cell_new()
cell->rep = CELL_REP_CRYST;
cell->pointgroup = strdup("1");
+ cell->spacegroup = strdup("P 1");
return cell;
}
@@ -90,6 +91,7 @@ void cell_free(UnitCell *cell)
{
if ( cell == NULL ) return;
free(cell->pointgroup);
+ free(cell->spacegroup);
free(cell);
}
@@ -187,6 +189,8 @@ UnitCell *cell_new_from_cell(UnitCell *orig)
new = malloc(sizeof(UnitCell));
*new = *orig;
+ cell_set_pointgroup(new, orig->pointgroup);
+ cell_set_spacegroup(new, orig->spacegroup);
return new;
}
@@ -207,6 +211,20 @@ void cell_set_reciprocal(UnitCell *cell,
}
+void cell_set_spacegroup(UnitCell *cell, const char *sym)
+{
+ free(cell->spacegroup);
+ cell->spacegroup = strdup(sym);
+}
+
+
+void cell_set_pointgroup(UnitCell *cell, const char *sym)
+{
+ free(cell->pointgroup);
+ cell->pointgroup = strdup(sym);
+}
+
+
/************************* Getter helper functions ****************************/
static int cell_crystallographic_to_cartesian(UnitCell *cell,
@@ -838,8 +856,7 @@ static void cell_set_pointgroup_from_pdb(UnitCell *cell, const char *sym)
if ( strcmp(sym, "P 43 21 2") == 0 ) new = "422";
if ( new != NULL ) {
- free(cell->pointgroup);
- cell->pointgroup = strdup(new);
+ cell_set_pointgroup(cell, new);
} else {
ERROR("Can't determine point group for '%s'\n", sym);
}
@@ -901,13 +918,15 @@ UnitCell *load_cell_from_pdb(const char *filename)
sym = strndup(line+55, 10);
notrail(sym);
cell_set_pointgroup_from_pdb(cell, sym);
- cell->spacegroup = sym;
-
+ cell_set_spacegroup(cell, sym);
+ free(sym);
} else {
cell_set_pointgroup_from_pdb(cell, "P 1");
- cell->spacegroup = strdup("P 1");
+ cell_set_spacegroup(cell, "P 1");
ERROR("CRYST1 line without space group.\n");
}
+
+ break; /* Done */
}
} while ( rval != NULL );