summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2012-09-29 20:57:48 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2012-09-29 20:58:26 -0700
commit24c6197c1019e8a3e7e5924522071be5a68a7be9 (patch)
treec59de59d3448063acf253371b8453a4b88be5e3b
parent12ca6112e5a6f8e5ec8e1fee09976ef973f99680 (diff)
downloadsubsurface-24c6197c1019e8a3e7e5924522071be5a68a7be9.tar.gz
Fix a number of obvious memory leaks
Just the result of cppcheck and valgrind... Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--divelist.c3
-rw-r--r--gtk-gui.c2
-rw-r--r--main.c1
-rw-r--r--parse-xml.c1
-rw-r--r--uemis-downloader.c33
5 files changed, 23 insertions, 17 deletions
diff --git a/divelist.c b/divelist.c
index 7f9095951..05e46bc93 100644
--- a/divelist.c
+++ b/divelist.c
@@ -1423,6 +1423,9 @@ static int copy_tree_node(GtkTreeIter *a, GtkTreeIter *b)
DIVE_OTU, store_dive.otu,
DIVE_LOCATION, store_dive.location,
-1);
+ free(cylinder_text);
+ free(store_dive.location);
+ free(store_dive.suit);
return idx;
}
diff --git a/gtk-gui.c b/gtk-gui.c
index 0c74675a4..7032b1a04 100644
--- a/gtk-gui.c
+++ b/gtk-gui.c
@@ -1027,7 +1027,7 @@ void init_ui(int *argcp, char ***argvp)
if (!conf_value)
uemis_max_dive_data = strdup("");
else
- uemis_max_dive_data = strdup(conf_value);
+ uemis_max_dive_data = conf_value;
error_info_bar = NULL;
win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
g_set_application_name ("subsurface");
diff --git a/main.c b/main.c
index 95f63713d..7101b8b87 100644
--- a/main.c
+++ b/main.c
@@ -259,6 +259,7 @@ int main(int argc, char **argv)
/* don't report errors - this file may not exist, but make
sure we remember this as the filename in use */
set_filename(filename, FALSE);
+ free((void *)filename);
}
report_dives(imported);
if (dive_table.nr == 0)
diff --git a/parse-xml.c b/parse-xml.c
index da150d27e..90ad91c79 100644
--- a/parse-xml.c
+++ b/parse-xml.c
@@ -1270,6 +1270,7 @@ static void entry(const char *name, int size, const char *raw)
try_to_fill_dive(&cur_dive, name, buf);
return;
}
+ free(buf);
}
static const char *nodename(xmlNode *node, char *buf, int len)
diff --git a/uemis-downloader.c b/uemis-downloader.c
index 75eca6acc..1fec353a8 100644
--- a/uemis-downloader.c
+++ b/uemis-downloader.c
@@ -403,6 +403,7 @@ static gboolean uemis_get_answer(const char *path, char *request, int n_param_in
for (i = 0; i < n_param_out && j < size; i++)
param_buff[i] = next_segment(buf, &j, size);
found_answer = TRUE;
+ free(buf);
}
#if UEMIS_DEBUG
for (i = 0; i < n_param_out; i++)
@@ -544,9 +545,8 @@ static char *do_uemis_download(struct argument_block *args)
char **max_dive_data = args->max_dive_data;
char **xml_buffer = args->xml_buffer;
int xml_buffer_size;
- char *error_text = "";
char *newmax = NULL;
- char *deviceid;
+ char *deviceid = NULL;
char *result = NULL;
char *endptr;
gboolean success;
@@ -555,34 +555,33 @@ static char *do_uemis_download(struct argument_block *args)
uemis_info("Init Communication");
if (! uemis_init(mountpath))
return "Uemis init failed";
- if (! uemis_get_answer(mountpath, "getDeviceId", 0, 1, &error_text))
- return error_text;
+ if (! uemis_get_answer(mountpath, "getDeviceId", 0, 1, &result))
+ goto bail;
deviceid = strdup(param_buff[0]);
/* the answer from the DeviceId call becomes the input parameter for getDeviceData */
- if (! uemis_get_answer(mountpath, "getDeviceData", 1, 0, &error_text))
- return error_text;
+ if (! uemis_get_answer(mountpath, "getDeviceData", 1, 0, &result))
+ goto bail;
/* param_buff[0] is still valid */
- if (! uemis_get_answer(mountpath, "initSession", 1, 6, &error_text))
- return error_text;
+ if (! uemis_get_answer(mountpath, "initSession", 1, 6, &result))
+ goto bail;
uemis_info("Start download");
- if (! uemis_get_answer(mountpath, "processSync", 0, 2, &error_text))
- return error_text;
+ if (! uemis_get_answer(mountpath, "processSync", 0, 2, &result))
+ goto bail;
param_buff[1] = "notempty";
newmax = get_divenr(*max_dive_data, deviceid);
for (;;) {
param_buff[2] = newmax;
param_buff[3] = 0;
- success = uemis_get_answer(mountpath, "getDivelogs", 3, 0, &error_text);
+ success = uemis_get_answer(mountpath, "getDivelogs", 3, 0, &result);
/* process the buffer we have assembled */
if (mbuf) {
char *next_seg = process_raw_buffer(mbuf, &newmax);
buffer_add(xml_buffer, &xml_buffer_size, next_seg);
+ free(next_seg);
}
/* if we got an error, deal with it */
- if (!success) {
- result = error_text;
+ if (!success)
break;
- }
/* also, if we got nothing back, we should stop trying */
if (!param_buff[3])
break;
@@ -598,8 +597,8 @@ static char *do_uemis_download(struct argument_block *args)
}
*args->max_dive_data = update_max_dive_data(*max_dive_data, deviceid, newmax);
free(newmax);
- if (! uemis_get_answer(mountpath, "terminateSync", 0, 3, &error_text))
- return error_text;
+ if (! uemis_get_answer(mountpath, "terminateSync", 0, 3, &result))
+ goto bail;
if (! strcmp(param_buff[0], "error")) {
if (! strcmp(param_buff[2],"Out of Memory"))
result = ERR_FS_FULL;
@@ -610,6 +609,8 @@ static char *do_uemis_download(struct argument_block *args)
#if UEMIS_DEBUG > 5
fprintf(debugfile, "XML buffer \"%s\"", *xml_buffer);
#endif
+bail:
+ free(deviceid);
return result;
}