summaryrefslogtreecommitdiffstats
path: root/parse-xml.c
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2015-06-21 20:24:07 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-06-21 21:13:32 -0700
commitf5726c3d184dce88822fd84dbe994d6fa92c089b (patch)
treeea5f96a9a81a4f07b3425bad134ed9a4959aa10f /parse-xml.c
parent004705e33e450c52d6753c55797885aedb6ad769 (diff)
downloadsubsurface-f5726c3d184dce88822fd84dbe994d6fa92c089b.tar.gz
Fix a number of resource leaks
Free memory returned from parse_mkvi_value() Free memory returned from printGPSCoords() Free memory allocated in added_list and removed_list Free memory allocated when adding suffix to dive site name Free memory allocated in cache_deco_state() Free memory allocated in build_filename() Free memory allocated in get_utf8() Free memory allocated in alloc_dive() Free memory allocated as cache but never used Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'parse-xml.c')
-rw-r--r--parse-xml.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/parse-xml.c b/parse-xml.c
index 0e8e3a556..9b5f97e21 100644
--- a/parse-xml.c
+++ b/parse-xml.c
@@ -1204,8 +1204,9 @@ static void gps_in_dive(char *buffer, struct dive *dive)
fprintf(stderr, "dive site uuid in dive, but gps location (%10.6f/%10.6f) different from dive location (%10.6f/%10.6f)\n",
ds->latitude.udeg / 1000000.0, ds->longitude.udeg / 1000000.0,
latitude.udeg / 1000000.0, longitude.udeg / 1000000.0);
- ds->notes = add_to_string(ds->notes, translate("gettextFromC", "multiple gps locations for this dive site; also %s\n"),
- printGPSCoords(latitude.udeg, longitude.udeg));
+ const char *coords = printGPSCoords(latitude.udeg, longitude.udeg);
+ ds->notes = add_to_string(ds->notes, translate("gettextFromC", "multiple gps locations for this dive site; also %s\n"), coords);
+ free((void *)coords);
} else {
fprintf(stderr, "let's add the gps coordinates to divesite with uuid %8x and name %s\n", ds->uuid, ds->name ?: "(none)");
ds->latitude = latitude;
@@ -1220,6 +1221,7 @@ static void add_dive_site(char *ds_name, struct dive *dive)
{
static int suffix = 1;
char *buffer = ds_name;
+ char *to_free = NULL;
fprintf(stderr, "add_dive_site with name %s\n", buffer);
int size = trimspace(buffer);
if(size) {
@@ -1238,7 +1240,7 @@ static void add_dive_site(char *ds_name, struct dive *dive)
// get a lot of dives with identical names (the autogenerated fixes).
// So in this case modify the name to make it unique
int name_size = strlen(buffer) + 10; // 8 digits - enough for 100 million sites
- buffer = malloc(name_size);
+ to_free = buffer = malloc(name_size);
do {
suffix++;
snprintf(buffer, name_size, "%s %8d", ds_name, suffix);
@@ -1276,6 +1278,7 @@ static void add_dive_site(char *ds_name, struct dive *dive)
dive->dive_site_uuid = create_dive_site(buffer);
}
}
+ free(to_free);
}
static void gps_picture_location(char *buffer, struct picture *pic)