We only use three levels of taxonomy, but we were attempting to free memory
for seven.  This led to some fun invalid point crashes.

Please check I'm not way off the mark, but it definitely appears to fix the
crashes I was getting.

Cheers,

Rick
From 74eaf6509c08bbf08fbb8cbae1fe3de97dca1ce6 Mon Sep 17 00:00:00 2001
From: Rick Walsh <[email protected]>
Date: Mon, 13 Jul 2015 22:34:10 +1000
Subject: [PATCH] Only free memory for three levels of taxonomy

We only use three levels of taxonomy, but we were attempting to free memory
for seven.  This led to some fun invalid point crashes.

Signed-off-by: Rick Walsh <[email protected]>
---
 taxonomy.c | 2 +-
 taxonomy.h | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/taxonomy.c b/taxonomy.c
index b72616f..1232944 100644
--- a/taxonomy.c
+++ b/taxonomy.c
@@ -31,7 +31,7 @@ struct taxonomy *alloc_taxonomy()
 void free_taxonomy(struct taxonomy *t)
 {
 	if (t) {
-		for (int i = 0; i < TC_NR_CATEGORIES; i++)
+		for (int i = 0; i < MAX_TAXONOMY_LEVELS; i++)
 			free((void *)t[i].value);
 		free(t);
 	}
diff --git a/taxonomy.h b/taxonomy.h
index 9831cfe..9ac6039 100644
--- a/taxonomy.h
+++ b/taxonomy.h
@@ -5,6 +5,8 @@
 extern "C" {
 #endif
 
+#define MAX_TAXONOMY_LEVELS (3)
+
 enum taxonomy_category {
 	TC_NONE,
 	TC_OCEAN,
-- 
2.4.3

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

Reply via email to