[PATCH 6/6] gps.c: Make two more memory leak fixes and a small coding style change

Lubomir I. Ivanov neolit123 at gmail.com
Sat Feb 9 11:30:01 PST 2013


From: "Lubomir I. Ivanov" <neolit123 at gmail.com>

1)
add_gps_point():
Apparently osm_gps_map_point_new_*() is leaking memory if the
point struct is not freed after the point is added to the
map osm_gps_map_track_add_point().

However the API for releasing a point is missing on
older Windows builds of the map library, so instead of
osm_gps_map_point_free() we simply call:
	free((void *)point);

2)
init_map()
According to memory management tools
osm_gps_map_get_default_cache_directory() is using g_realloc
for eventual string expansion therefore we have to release at the
returned pointer.

3)
add_gps_point()
Also a small coding style change is made:
move the pointer symbol (*) near the name of the variable
instead of leaving spaces on both sides, like:
<type> * <name>

Signed-off-by: Lubomir I. Ivanov <neolit123 at gmail.com>

...

Signed-off-by: Lubomir I. Ivanov <neolit123 at gmail.com>
---
 gps.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/gps.c b/gps.c
index 23e0de0..6c06444 100644
--- a/gps.c
+++ b/gps.c
@@ -135,10 +135,11 @@ static gboolean scroll_cb(GtkWidget *widget, GdkEventScroll *event, gpointer dat
 
 static void add_gps_point(OsmGpsMap *map, float latitude, float longitude)
 {
-	OsmGpsMapTrack * track = osm_gps_map_track_new();
-	OsmGpsMapPoint * point = osm_gps_map_point_new_degrees(latitude, longitude);
+	OsmGpsMapTrack *track = osm_gps_map_track_new();
+	OsmGpsMapPoint *point = osm_gps_map_point_new_degrees(latitude, longitude);
 	osm_gps_map_track_add_point(track, point);
 	osm_gps_map_track_add(map, track);
+	free((void *)point);
 }
 
 static void key_press_event(GtkWidget *window, GdkEventKey *event, gpointer data)
@@ -177,6 +178,7 @@ OsmGpsMap *init_map(void)
 
 	osm_gps_map_layer_add(OSM_GPS_MAP(map), osd);
 	g_object_unref(G_OBJECT(osd));
+	free((void*)cachebasedir);
 	return map;
 }
 
-- 
1.7.11.msysgit.0



More information about the subsurface mailing list