[grits] Fix memory leaks
- From: Andy Spencer <andys src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [grits] Fix memory leaks
- Date: Tue, 3 Jan 2012 01:19:39 +0000 (UTC)
commit 81d8f34cc62ae85d9243ad0eb8c4587282c11710
Author: Andy Spencer <andy753421 gmail com>
Date: Thu Oct 27 07:18:02 2011 +0000
Fix memory leaks
src/.vimrc | 2 +-
src/Makefile.am | 2 +-
src/data/grits-http.c | 16 +++++++++-------
src/grits-test.c | 5 +++++
src/gtk.suppression | 9 +++++++++
src/objects/grits-poly.c | 21 ++++++++++++++++++---
6 files changed, 43 insertions(+), 12 deletions(-)
---
diff --git a/src/.vimrc b/src/.vimrc
index 2dd1127..df75c3f 100644
--- a/src/.vimrc
+++ b/src/.vimrc
@@ -1,5 +1,5 @@
set makeprg=make\ test
"set tw=100
-au FileType valgrind syn match gritsFile "\v<(grits-\w+|roam|elev|env|map|sat|test|radar)\.c>" containedin=valgrindSrc
+au FileType valgrind syn match gritsFile "\v<(grits-\w+|roam|elev|env|map|sat|test|radar|alert)\.c>" containedin=valgrindSrc
au FileType valgrind hi link gritsFile Error
diff --git a/src/Makefile.am b/src/Makefile.am
index c4ad298..cc17c40 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -98,5 +98,5 @@ memcheck: all
--num-callers=50 \
--suppressions=gtk.suppression \
--suppressions=/usr/lib/valgrind/default.supp \
- ./grits-test \
+ .libs/grits-test \
2> valgrind.out
diff --git a/src/data/grits-http.c b/src/data/grits-http.c
index 3b0c83e..8880d74 100644
--- a/src/data/grits-http.c
+++ b/src/data/grits-http.c
@@ -192,26 +192,28 @@ gchar *grits_http_fetch(GritsHttp *http, const gchar *uri, const char *local,
/* Close file */
fclose(fp);
- if (path != part && SOUP_STATUS_IS_SUCCESSFUL(message->status_code)) {
- g_rename(part, path);
+ if (path != part) {
+ if (SOUP_STATUS_IS_SUCCESSFUL(message->status_code))
+ g_rename(part, path);
g_free(part);
}
/* Finished */
- if (message->status_code == SOUP_STATUS_CANCELLED) {
+ guint status = message->status_code;
+ g_object_unref(message);
+ if (status == SOUP_STATUS_CANCELLED) {
return NULL;
- } else if (message->status_code == SOUP_STATUS_REQUESTED_RANGE_NOT_SATISFIABLE) {
+ } else if (status == SOUP_STATUS_REQUESTED_RANGE_NOT_SATISFIABLE) {
/* Range unsatisfiable, file already complete */
- } else if (!SOUP_STATUS_IS_SUCCESSFUL(message->status_code)) {
+ } else if (!SOUP_STATUS_IS_SUCCESSFUL(status)) {
g_warning("GritsHttp: done_cb - error copying file, status=%d\n"
"\tsrc=%s\n"
"\tdst=%s",
- message->status_code, uri, path);
+ status, uri, path);
return NULL;
}
}
-
/* TODO: free everything.. */
return path;
}
diff --git a/src/grits-test.c b/src/grits-test.c
index 5be869b..695f4f9 100644
--- a/src/grits-test.c
+++ b/src/grits-test.c
@@ -100,5 +100,10 @@ int main(int argc, char **argv)
gdk_threads_leave();
gdk_display_close(gdk_display_get_default());
+
+ prefs = NULL;
+ plugins = NULL;
+ viewer = NULL;
+ window = vbox = config = NULL;
return 0;
}
diff --git a/src/gtk.suppression b/src/gtk.suppression
index 4365b95..aab9a83 100644
--- a/src/gtk.suppression
+++ b/src/gtk.suppression
@@ -61,6 +61,15 @@
fun:g_module_symbol
fun:g_module_open
}
+{
+ g_class_ref__leak
+ Memcheck:Leak
+ fun:malloc
+ fun:g_malloc
+ fun:g_memdup
+ fun:type_iface_vtable_base_init_Wm
+ fun:g_type_class_ref
+}
# GTK+
{
diff --git a/src/objects/grits-poly.c b/src/objects/grits-poly.c
index 1a1e614..720e3b1 100644
--- a/src/objects/grits-poly.c
+++ b/src/objects/grits-poly.c
@@ -114,6 +114,12 @@ static void grits_poly_pick(GritsObject *_poly, GritsOpenGL *opengl)
glPopAttrib();
}
+static gboolean grits_poly_delete(gpointer list)
+{
+ glDeleteLists((guint)list, 1);
+ return FALSE;
+}
+
/**
* grits_poly_new:
* @points: TODO
@@ -131,6 +137,13 @@ GritsPoly *grits_poly_new(gdouble (**points)[3])
return poly;
}
+static void _free_points(gdouble (**points)[3])
+{
+ for (int i = 0; points[i]; i++)
+ g_free(points[i]);
+ g_free(points);
+}
+
GritsPoly *grits_poly_parse(const gchar *str,
const gchar *poly_sep, const gchar *point_sep, const gchar *coord_sep)
{
@@ -164,6 +177,7 @@ GritsPoly *grits_poly_parse(const gchar *str,
polys[pi] = coords;
g_strfreev(scoords);
}
+ g_strfreev(spolys);
/* Create GritsPoly */
GritsPoly *poly = grits_poly_new(polys);
@@ -171,6 +185,7 @@ GritsPoly *grits_poly_parse(const gchar *str,
GRITS_OBJECT(poly)->center.lon = lon_avg(bounds.e, bounds.w);
GRITS_OBJECT(poly)->center.elev = 0;
GRITS_OBJECT(poly)->skip = GRITS_SKIP_CENTER;
+ g_object_weak_ref(G_OBJECT(poly), (GWeakNotify)_free_points, polys);
return poly;
}
@@ -188,10 +203,10 @@ static void grits_poly_init(GritsPoly *poly)
static void grits_poly_finalize(GObject *_poly)
{
- g_debug("GritsPoly: finalize");
+ //g_debug("GritsPoly: finalize");
GritsPoly *poly = GRITS_POLY(_poly);
- (void)poly;
- // TODO: free points
+ if (poly->list[0]) g_idle_add(grits_poly_delete, (gpointer)poly->list[0]);
+ if (poly->list[1]) g_idle_add(grits_poly_delete, (gpointer)poly->list[1]);
}
static void grits_poly_class_init(GritsPolyClass *klass)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]