From: Thadeu Lima de Souza Cascardo Date: Sat, 2 Aug 2008 14:21:37 +0000 (-0300) Subject: Does not leak memory with ctx and backend X-Git-Url: http://git.cascardo.eti.br/?p=cascardo%2Fatompub.git;a=commitdiff_plain;h=45beb62bf81b395184ed36baba85b27c9456cdb8 Does not leak memory with ctx and backend --- diff --git a/include/atompub/backend.h b/include/atompub/backend.h index a76c7b8..5099ccd 100644 --- a/include/atompub/backend.h +++ b/include/atompub/backend.h @@ -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 *); diff --git a/include/atompub/ctx.h b/include/atompub/ctx.h index 5fef349..35ecca6 100644 --- a/include/atompub/ctx.h +++ b/include/atompub/ctx.h @@ -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 *); diff --git a/src/backend.c b/src/backend.c index 04ff695..ded8229 100644 --- a/src/backend.c +++ b/src/backend.c @@ -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 *, diff --git a/src/ctx.c b/src/ctx.c index 8904b38..73f17fc 100644 --- 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) { diff --git a/src/main.c b/src/main.c index c6781a6..2a790d0 100644 --- a/src/main.c +++ b/src/main.c @@ -43,5 +43,6 @@ main (int argc, char **argv) exit (1); } cgi_serve_request (ctx); + atom_ctx_delete (ctx); return 0; }