summaryrefslogtreecommitdiffstats
path: root/divelist.c
diff options
context:
space:
mode:
authorGravatar Lubomir I. Ivanov <neolit123@gmail.com>2012-10-02 01:52:44 +0300
committerGravatar Dirk Hohndel <dirk@hohndel.org>2012-10-01 20:56:17 -0700
commitfa5afc697e664a93fc754e50dbfd15b2333028e7 (patch)
treee903089de879d46b5c55d1a644b5839add7fbc1d /divelist.c
parentcfefa0206dce3e144ee51383d81a146719b64737 (diff)
downloadsubsurface-fa5afc697e664a93fc754e50dbfd15b2333028e7.tar.gz
Fix memory leaks related to dive_trip->location
When creating a new dive_trip from a dive, we should probably always copy the location via strdup(). However we then have to take care of the de-allocation in divelist.c:delete_trip() and gtk-gui.c:file_close(). Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'divelist.c')
-rw-r--r--divelist.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/divelist.c b/divelist.c
index 9bdee1571..e09eca5f9 100644
--- a/divelist.c
+++ b/divelist.c
@@ -1023,6 +1023,9 @@ void insert_trip(dive_trip_t **dive_trip_p)
static inline void delete_trip(GList *trip)
{
+ dive_trip_t *dive_trip = (dive_trip_t *)g_list_nth_data(trip, 0);
+ if (dive_trip->location)
+ free(dive_trip->location);
dive_trip_list = g_list_delete_link(dive_trip_list, trip);
#ifdef DEBUG_TRIP
dump_trip_list();
@@ -1169,7 +1172,7 @@ static void fill_dive_list(void)
if (dive_trip->when > dive->when)
dive_trip->when = dive->when;
if (!dive_trip->location && dive->location)
- dive_trip->location = dive->location;
+ dive_trip->location = strdup(dive->location);
if (dive_trip != last_trip) {
last_trip = dive_trip;
/* create trip entry */