[PATCH 4/4] Fix memory leaks related to dive_trip->location
Dirk Hohndel
dirk at hohndel.org
Mon Oct 1 21:03:13 PDT 2012
Yes, this seems to be the right solution.
All of your recent patches have been applied and pushed.
As always, thanks for your hard work on Subsurface.
I am amazed how much a non-diver is contributing to our little project.
I so want to invite you to go diving one day :-)
/D
"Lubomir I. Ivanov" <neolit123 at gmail.com> writes:
> From: "Lubomir I. Ivanov" <neolit123 at gmail.com>
>
> 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 at gmail.com>
> ---
> divelist.c | 5 ++++-
> gtk-gui.c | 10 +++++++++-
> 2 files changed, 13 insertions(+), 2 deletions(-)
>
> diff --git a/divelist.c b/divelist.c
> index 9bdee15..e09eca5 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 */
> diff --git a/gtk-gui.c b/gtk-gui.c
> index 5a680c7..9976942 100644
> --- a/gtk-gui.c
> +++ b/gtk-gui.c
> @@ -251,6 +251,14 @@ static gboolean ask_save_changes()
> return quit;
> }
>
> +static void dive_trip_unref(gpointer data, gpointer user_data)
> +{
> + dive_trip_t *dive_trip = (dive_trip_t *)data;
> + if (dive_trip->location)
> + free(dive_trip->location);
> + free(data);
> +}
> +
> static void file_close(GtkWidget *w, gpointer data)
> {
> int i;
> @@ -271,7 +279,7 @@ static void file_close(GtkWidget *w, gpointer data)
> mark_divelist_changed(FALSE);
>
> /* inlined version of g_list_free_full(dive_trip_list, free); */
> - g_list_foreach(dive_trip_list, (GFunc)free, NULL);
> + g_list_foreach(dive_trip_list, (GFunc)dive_trip_unref, NULL);
> g_list_free(dive_trip_list);
>
> dive_trip_list = NULL;
> --
> 1.7.11.msysgit.0
>
> _______________________________________________
> subsurface mailing list
> subsurface at hohndel.org
> http://lists.hohndel.org/cgi-bin/mailman/listinfo/subsurface
--
Dirk Hohndel
Intel Open Source Technology Center
More information about the subsurface
mailing list