diff options
-rw-r--r-- | commands/command_edit.cpp | 2 | ||||
-rw-r--r-- | core/equipment.c | 8 | ||||
-rw-r--r-- | core/equipment.h | 1 |
3 files changed, 8 insertions, 3 deletions
diff --git a/commands/command_edit.cpp b/commands/command_edit.cpp index d0d9fc087..61b2f0d7a 100644 --- a/commands/command_edit.cpp +++ b/commands/command_edit.cpp @@ -1031,7 +1031,7 @@ RemoveWeight::RemoveWeight(int index, bool currentDiveOnly) : RemoveWeight::~RemoveWeight() { - free((void *)ws.description); + free_weightsystem(ws); } bool RemoveWeight::workToBeDone() diff --git a/core/equipment.c b/core/equipment.c index bd1a0b4e3..e7ac327fd 100644 --- a/core/equipment.c +++ b/core/equipment.c @@ -19,9 +19,13 @@ #include "subsurface-string.h" #include "table.h" -static void free_weightsystem(weightsystem_t w) +/* Warning: this has strange semantics for C-code! Not the weightsystem object + * is freed, but the data it references. The object itself is passed in by value. + * This is due to the fact how the table macros work. + */ +void free_weightsystem(weightsystem_t ws) { - free((void *)w.description); + free((void *)ws.description); } static void free_cylinder(cylinder_t c) diff --git a/core/equipment.h b/core/equipment.h index 2711d7703..77fd9c430 100644 --- a/core/equipment.h +++ b/core/equipment.h @@ -70,6 +70,7 @@ struct weightsystem_table { extern int cylinderuse_from_text(const char *text); extern void copy_weights(const struct weightsystem_table *s, struct weightsystem_table *d); extern weightsystem_t clone_weightsystem(weightsystem_t ws); +extern void free_weightsystem(weightsystem_t ws); extern void copy_cylinder_types(const struct dive *s, struct dive *d); extern void add_cloned_weightsystem(struct weightsystem_table *t, weightsystem_t ws); extern cylinder_t *add_empty_cylinder(struct cylinder_table *t); |