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>
This commit is contained in:
Dirk Hohndel 2015-06-21 20:24:07 -07:00
parent 004705e33e
commit f5726c3d18
8 changed files with 26 additions and 11 deletions

View file

@ -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)