diff options
-rw-r--r-- | dive.c | 9 | ||||
-rw-r--r-- | divelist.c | 11 |
2 files changed, 16 insertions, 4 deletions
@@ -734,13 +734,14 @@ add_sample_b: static char *merge_text(const char *a, const char *b) { char *res; - + if (!a && !b) + return NULL; if (!a || !*a) - return (char *)b; + return strdup(b); if (!b || !*b) - return (char *)a; + return strdup(a); if (!strcmp(a,b)) - return (char *)a; + return strdup(a); res = malloc(strlen(a) + strlen(b) + 9); if (!res) return (char *)a; diff --git a/divelist.c b/divelist.c index 08246738f..bd610ac0a 100644 --- a/divelist.c +++ b/divelist.c @@ -1947,7 +1947,18 @@ void delete_single_dive(int idx) dive_table.nr--; if (dive->selected) amount_selected--; + /* free all allocations */ free(dive->dc.sample); + if (dive->location) + free((void *)dive->location); + if (dive->notes) + free((void *)dive->notes); + if (dive->divemaster) + free((void *)dive->divemaster); + if (dive->buddy) + free((void *)dive->buddy); + if (dive->suit) + free((void *)dive->suit); free(dive); } |