I attached the rebased patches.
I also created a new one for the white spaces fix, as Lubomir suggested.

Happy hacking,
Claudiu


>>
>> Are you going to rebase them on the latest master?
>>
>> /D
>>
>
>
From 0b7abc44e7c89edcdf8a7a892f9897a4c03b6229 Mon Sep 17 00:00:00 2001
From: Claudiu Olteanu <[email protected]>
Date: Mon, 23 Mar 2015 20:08:39 +0200
Subject: [PATCH 1/5] Resolve some memory leak on datatrak source

The result of byte_to_bits should be freed by the caller.
This patch frees the memory allocated by that function.
Also there were some memory leaks in data_import and
read_file_header functions when an error occured.

Signed-off-by: Claudiu Olteanu <[email protected]>
---
 datatrak.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/datatrak.c b/datatrak.c
index 7357b05..f98aebd 100644
--- a/datatrak.c
+++ b/datatrak.c
@@ -120,6 +120,8 @@ static struct sample *dtrak_profile(struct dive *dt_dive, FILE *archivo)
 			}
 			j = 0;
 		}
+		free(byte);
+
 		// In commit 5f44fdd setpoint replaced po2, so although this is not necesarily CCR dive ...
 		if (is_O2)
 			sample->setpoint.mbar = calculate_depth_to_mbar(sample->depth.mm, dt_dive->surface_pressure, 0) * o2percent / 100;
@@ -141,6 +143,7 @@ static dtrakheader read_file_header(FILE *archivo)
 	fread(lector, 1, headerbytes, archivo);
 	if (two_bytes_to_int(lector[0], lector[1]) != 0xA100) {
 		report_error(translate("gettextFromC", "Error: the file does not appear to be a DATATRAK divelog"));
+		free(lector);
 		return fileheader;
 	}
 	fileheader.header = (lector[0] << 8) + lector[1];
@@ -393,6 +396,7 @@ static struct dive dt_dive_parser(FILE *archivo, struct dive *dt_dive)
 		taglist_add_tag(&dt_dive->tag_list, strdup(QT_TRANSLATE_NOOP("gettextFromC", "fresh")));
 	if (byte[7] != 0)
 		taglist_add_tag(&dt_dive->tag_list, strdup(QT_TRANSLATE_NOOP("gettextFromC", "salt water")));
+	free(byte);
 
 	/*
 	 * Dive Type 2 - Bit table, use tags again
@@ -408,6 +412,7 @@ static struct dive dt_dive_parser(FILE *archivo, struct dive *dt_dive)
 		is_SCR = 1;
 		dt_dive->dc.divemode = PSCR;
 	}
+	free(byte);
 
 	/*
 	 *  Dive Activity 1 - Bit table, use tags again
@@ -430,6 +435,7 @@ static struct dive dt_dive_parser(FILE *archivo, struct dive *dt_dive)
 		taglist_add_tag(&dt_dive->tag_list, strdup(QT_TRANSLATE_NOOP("gettextFromC", "ice")));
 	if (byte[7] != 0)
 		taglist_add_tag(&dt_dive->tag_list, strdup(QT_TRANSLATE_NOOP("gettextFromC", "search")));
+	free(byte);
 
 
 	/*
@@ -447,6 +453,7 @@ static struct dive dt_dive_parser(FILE *archivo, struct dive *dt_dive)
 		taglist_add_tag(&dt_dive->tag_list, strdup(QT_TRANSLATE_NOOP("gettextFromC", "photo")));
 	if (byte[4] != 0)
 		taglist_add_tag(&dt_dive->tag_list, strdup(QT_TRANSLATE_NOOP("gettextFromC", "other")));
+	free(byte);
 
 	/*
 	 * Other activities - String  1st byte = long
@@ -653,6 +660,7 @@ void datatrak_import(const char *file, struct dive_table *table)
 
 	if ((archivo = subsurface_fopen(file, "rb")) == NULL) {
 		report_error(translate("gettextFromC", "Error: couldn't open the file %s"), file);
+		free(fileheader);
 		return;
 	}
 
-- 
2.1.4

From 12e7ed7d3da5848e3bf3db72693c079ea1479ded Mon Sep 17 00:00:00 2001
From: Claudiu Olteanu <[email protected]>
Date: Mon, 23 Mar 2015 20:11:57 +0200
Subject: [PATCH 2/5] Remove some white spaces in order to be compliant with
 coding standards

Signed-off-by: Claudiu Olteanu <[email protected]>
---
 datatrak.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/datatrak.c b/datatrak.c
index f98aebd..537b09d 100644
--- a/datatrak.c
+++ b/datatrak.c
@@ -401,7 +401,7 @@ static struct dive dt_dive_parser(FILE *archivo, struct dive *dt_dive)
 	/*
 	 * Dive Type 2 - Bit table, use tags again
 	 */
-	read_bytes (1);
+	read_bytes(1);
 	byte = byte_to_bits(tmp_1byte);
 	if (byte[0] != 0) {
 		taglist_add_tag(&dt_dive->tag_list, strdup("nitrox"));
@@ -679,5 +679,5 @@ void datatrak_import(const char *file, struct dive_table *table)
 	taglist_cleanup(&g_tag_list);
 	fclose(archivo);
 	sort_table(table);
-	free (fileheader);
+	free(fileheader);
 }
-- 
2.1.4

From 43457383f6bfe28d4a2eafc327171ac066e8d637 Mon Sep 17 00:00:00 2001
From: Claudiu Olteanu <[email protected]>
Date: Mon, 23 Mar 2015 20:17:27 +0200
Subject: [PATCH 3/5] Fix memory leaks on Cochran file

Free the buffer before terminating the process.

Signed-off-by: Claudiu Olteanu <[email protected]>
---
 cochran.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/cochran.c b/cochran.c
index 855ca7c..fe65ee2 100644
--- a/cochran.c
+++ b/cochran.c
@@ -233,6 +233,7 @@ static void cochran_parse_header(const unsigned char *decode, unsigned mod,
 		break;
 	default:
 		printf ("Unknown log format v%c\n", buf[0x137]);
+		free(buf);
 		exit(1);
 		break;
 	}
-- 
2.1.4

From 2eb2ec38438da12b74b96be8ca60e8e3ec29a3bc Mon Sep 17 00:00:00 2001
From: Claudiu Olteanu <[email protected]>
Date: Mon, 23 Mar 2015 20:22:55 +0200
Subject: [PATCH 5/5] Clean req.txt file path

This patch cleans the path allocated for req.txt file path.

Signed-off-by: Claudiu Olteanu <[email protected]>
---
 uemis-downloader.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/uemis-downloader.c b/uemis-downloader.c
index 3f22253..521cd7e 100644
--- a/uemis-downloader.c
+++ b/uemis-downloader.c
@@ -861,8 +861,10 @@ const char *do_uemis_import(device_data_t *data)
 	if (dive_table.nr == 0)
 		keep_number = true;
 	uemis_info(translate("gettextFromC", "Initialise communication"));
-	if (!uemis_init(mountpath))
+	if (!uemis_init(mountpath)) {
+		free(reqtxt_path);
 		return translate("gettextFromC", "Uemis init failed");
+	}
 	if (!uemis_get_answer(mountpath, "getDeviceId", 0, 1, &result))
 		goto bail;
 	deviceid = strdup(param_buff[0]);
@@ -994,5 +996,6 @@ bail:
 			result = param_buff[2];
 	}
 	free(deviceid);
+	free(reqtxt_path);
 	return result;
 }
-- 
2.1.4

From b18efd34dd20571d82d3b218125d89c630a56131 Mon Sep 17 00:00:00 2001
From: Claudiu Olteanu <[email protected]>
Date: Mon, 23 Mar 2015 20:19:39 +0200
Subject: [PATCH 4/5] Fix a memory leak in parser-xml

Free the temporary memory alocated for a cobalt location.

Signed-off-by: Claudiu Olteanu <[email protected]>
---
 parse-xml.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/parse-xml.c b/parse-xml.c
index a42f8c8..0abcfcb 100644
--- a/parse-xml.c
+++ b/parse-xml.c
@@ -2637,6 +2637,7 @@ extern int cobalt_location(void *handle, int columns, char **data, char **column
 			free(location);
 			location = NULL;
 			cur_dive->dive_site_uuid = create_dive_site(tmp);
+			free(tmp);
 		} else {
 			location = strdup(data[0]);
 		}
-- 
2.1.4

_______________________________________________
subsurface mailing list
[email protected]
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface

Reply via email to