Does not leak memory with ctx and backend
authorThadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Sat, 2 Aug 2008 14:21:37 +0000 (11:21 -0300)
committerThadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Sat, 2 Aug 2008 14:21:37 +0000 (11:21 -0300)
include/atompub/backend.h
include/atompub/ctx.h
src/backend.c
src/ctx.c
src/main.c

index a76c7b8..5099ccd 100644 (file)
@@ -27,6 +27,7 @@
 typedef struct _atom_backend AtomBackend;
 
 AtomBackend *atom_backend_new (void);
+void atom_backend_delete (AtomBackend *);
 void atom_backend_retrieve_resource_set (AtomBackend *,
                                         Atom * (AtomCtx *, IRI *));
 Atom * atom_retrieve_resource (AtomCtx *, IRI *);
index 5fef349..35ecca6 100644 (file)
@@ -23,6 +23,7 @@
 typedef struct _atom_ctx AtomCtx;
 
 AtomCtx * atom_ctx_new (void);
+void atom_ctx_delete (AtomCtx *);
 void * atom_config_data (AtomCtx *);
 void atom_config_data_set (AtomCtx *, void *);
 
index 04ff695..ded8229 100644 (file)
@@ -33,6 +33,12 @@ atom_backend_new ()
   return backend;
 }
 
+void
+atom_backend_delete (AtomBackend *backend)
+{
+  g_slice_free (AtomBackend, backend);
+}
+
 void
 atom_backend_retrieve_resource_set (AtomBackend *backend,
                                    Atom *retrieve_resource (AtomCtx *,
index 8904b38..73f17fc 100644 (file)
--- a/src/ctx.c
+++ b/src/ctx.c
@@ -35,9 +35,20 @@ atom_ctx_new ()
   ctx = g_slice_new (AtomCtx);
   ctx->error = NULL;
   ctx->config_data = NULL;
+  ctx->backend = NULL;
   return ctx;
 }
 
+void
+atom_ctx_delete (AtomCtx *ctx)
+{
+  if (ctx->error)
+    g_error_free (ctx->error);
+  if (ctx->backend)
+    atom_backend_delete (ctx->backend);
+  g_slice_free (AtomCtx, ctx);
+}
+
 void
 atom_error_set (AtomCtx *ctx, GError *error)
 {
index c6781a6..2a790d0 100644 (file)
@@ -43,5 +43,6 @@ main (int argc, char **argv)
       exit (1);
     }
   cgi_serve_request (ctx);
+  atom_ctx_delete (ctx);
   return 0;
 }