aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Lubomir I. Ivanov <neolit123@gmail.com>2013-02-21 03:07:18 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-02-20 17:19:50 -0800
commit9a5818e92cee4c2052e4c44d8e9cec9dd5cd5f5c (patch)
treeedad717814aecba774e09a2812d6357531d99baf
parent26a973cf5f8540ed91e4fd9c63b9e40e0bc4dd96 (diff)
downloadsubsurface-9a5818e92cee4c2052e4c44d8e9cec9dd5cd5f5c.tar.gz
Fixed a memory leak in the divelist when moving with the keyboard
There were some small leaks before here, related to gtk_tree_iter_copy(), but there is another one in select_next_dive(): nextiter = gtk_tree_iter_copy(iter); This now requires a SJ near the epilog where we do the memory cleanup. Lets call this similar label consistently "free_iter" between select_prev_dive and select_next_dive. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--divelist.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/divelist.c b/divelist.c
index da8211666..75d525ea2 100644
--- a/divelist.c
+++ b/divelist.c
@@ -2729,11 +2729,11 @@ void select_next_dive(void)
if (!gtk_tree_model_iter_next(MODEL(dive_list), nextiter)) {
if (!gtk_tree_model_iter_parent(MODEL(dive_list), nextiter, iter)) {
/* we're at the last top level node */
- return;
+ goto free_iter;
}
if (!gtk_tree_model_iter_next(MODEL(dive_list), nextiter)) {
/* last trip */
- return;
+ goto free_iter;
}
}
gtk_tree_model_get(MODEL(dive_list), nextiter, DIVE_INDEX, &idx, -1);
@@ -2741,9 +2741,12 @@ void select_next_dive(void)
/* need the first child */
parent = gtk_tree_iter_copy(nextiter);
if (! gtk_tree_model_iter_children(MODEL(dive_list), nextiter, parent))
- return;
+ goto free_iter;
}
go_to_iter(selection, nextiter);
+free_iter:
+ if (nextiter)
+ gtk_tree_iter_free(nextiter);
if (parent)
gtk_tree_iter_free(parent);
gtk_tree_iter_free(iter);
@@ -2763,27 +2766,27 @@ void select_prev_dive(void)
if (!gtk_tree_path_prev(treepath)) {
if (!gtk_tree_model_iter_parent(MODEL(dive_list), &previter, iter))
/* we're at the last top level node */
- goto free_path;
+ goto free_iter;
gtk_tree_path_free(treepath);
treepath = gtk_tree_model_get_path(MODEL(dive_list), &previter);
if (!gtk_tree_path_prev(treepath))
/* first trip */
- goto free_path;
+ goto free_iter;
if (!gtk_tree_model_get_iter(MODEL(dive_list), &previter, treepath))
- goto free_path;
+ goto free_iter;
}
if (!gtk_tree_model_get_iter(MODEL(dive_list), &previter, treepath))
- goto free_path;
+ goto free_iter;
gtk_tree_model_get(MODEL(dive_list), &previter, DIVE_INDEX, &idx, -1);
if (idx < 0) {
/* need the last child */
parent = gtk_tree_iter_copy(&previter);
if (! gtk_tree_model_iter_nth_child(MODEL(dive_list), &previter, parent,
gtk_tree_model_iter_n_children(MODEL(dive_list), parent) - 1))
- goto free_path;
+ goto free_iter;
}
go_to_iter(selection, &previter);
-free_path:
+free_iter:
gtk_tree_path_free(treepath);
if (parent)
gtk_tree_iter_free(parent);