mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
gps.c: Use only one instance of the map object and window
Both show_gps_locations() and show_gps_location() have static local variables 'map' (OSM_TYPE_GPS_MAP) and 'window', so technically both would create their own instances of these objects. This patch promotes the two variables to global, so that only one instance per type ever exists. A memory leak that is addressed is at the flag pixbuf allocation, which has to be freed right after the image is added to the map: picture = gdk_pixbuf_from_pixdata(&flag_pixbuf, TRUE, NULL); ... gdk_pixbuf_unref(picture); There is also a heap-lifespan memory leak at: map = g_object_new(OSM_TYPE_GPS_MAP,... but GLib isn't exacly happy about us unrefing it right before exiting the GTK main loop, so no fix is provided for that unfortunately. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
ea21126f62
commit
801b0832ae
1 changed files with 4 additions and 4 deletions
8
gps.c
8
gps.c
|
@ -14,6 +14,9 @@
|
|||
#include <gdk-pixbuf/gdk-pixdata.h>
|
||||
#include "flag.h"
|
||||
|
||||
static GtkWidget *window = NULL;
|
||||
static OsmGpsMap *map = NULL;
|
||||
|
||||
/* Several map providers are available, such as OSM_GPS_MAP_SOURCE_OPENSTREETMAP
|
||||
and OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_SATELLITE. We should make more of
|
||||
them available from e.g. a pull-down menu */
|
||||
|
@ -209,8 +212,6 @@ void show_map(OsmGpsMap *map, GtkWidget **window, struct dive *dive, void (*call
|
|||
|
||||
void show_gps_location(struct dive *dive, void (*callback)(float, float))
|
||||
{
|
||||
static GtkWidget *window = NULL;
|
||||
static OsmGpsMap *map = NULL;
|
||||
GdkPixbuf *picture;
|
||||
GError *gerror = NULL;
|
||||
|
||||
|
@ -225,6 +226,7 @@ void show_gps_location(struct dive *dive, void (*callback)(float, float))
|
|||
picture = gdk_pixbuf_from_pixdata(&flag_pixbuf, TRUE, NULL);
|
||||
if (picture) {
|
||||
osm_gps_map_image_add_with_alignment(map, lat, lng, picture, 0, 1);
|
||||
gdk_pixbuf_unref(picture);
|
||||
} else {
|
||||
printf("error message: %s\n", gerror->message);
|
||||
}
|
||||
|
@ -236,8 +238,6 @@ void show_gps_location(struct dive *dive, void (*callback)(float, float))
|
|||
|
||||
void show_gps_locations()
|
||||
{
|
||||
static OsmGpsMap *map = NULL;
|
||||
static GtkWidget *window = NULL;
|
||||
struct dive *dive;
|
||||
int idx;
|
||||
|
||||
|
|
Loading…
Reference in a new issue