Does not leak memory with ctx and backend
[cascardo/atompub.git] / src / ctx.c
index e8e5868..73f17fc 100644 (file)
--- a/src/ctx.c
+++ b/src/ctx.c
@@ -25,16 +25,64 @@ struct _atom_ctx
 {
   GError *error;
   gpointer config_data;
+  AtomBackend *backend;
 };
 
+AtomCtx *
+atom_ctx_new ()
+{
+  AtomCtx *ctx;
+  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)
 {
+  if (ctx->error)
+    g_error_free (ctx->error);
   ctx->error = error;
 }
 
+GError *
+atom_error_get (AtomCtx *ctx)
+{
+  return ctx->error;
+}
+
 void *
 atom_config_data (AtomCtx *ctx)
 {
   return ctx->config_data;
 }
+
+void
+atom_config_data_set (AtomCtx *ctx, void *data)
+{
+  ctx->config_data = data;
+}
+
+AtomBackend *
+atom_backend (AtomCtx *ctx)
+{
+  return ctx->backend;
+}
+
+void
+atom_backend_set (AtomCtx *ctx, AtomBackend *backend)
+{
+  ctx->backend = backend;
+}