summaryrefslogtreecommitdiff
path: root/cethcan
diff options
context:
space:
mode:
authorDavid Lamparter <equinox@diac24.net>2013-10-10 23:20:40 +0000
committerroot <root@beaglebone.local.sublab.org>2013-10-10 23:20:40 +0000
commitf12be4da8d9520be572c142ae276f3b96f292fee (patch)
tree6917fc20de5c9a0f35f9130603985ca2e4a96f36 /cethcan
parentecfa61ab231482d6403add3f163250564824fc62 (diff)
cethcan: fix memory management
- primary config structure no longer left allocated in main() - memleak in RPC result buffer handling
Diffstat (limited to 'cethcan')
-rw-r--r--cethcan/beanctr.c2
-rw-r--r--cethcan/main.c2
-rw-r--r--cethcan/rpc.c4
3 files changed, 7 insertions, 1 deletions
diff --git a/cethcan/beanctr.c b/cethcan/beanctr.c
index d381c79..9495376 100644
--- a/cethcan/beanctr.c
+++ b/cethcan/beanctr.c
@@ -83,7 +83,9 @@ int bean_init_conf(json_t *config)
b->name = strdup(json_string_value(json_object_get(config, "name")));
b->logical_addr = json_integer_value(json_object_get(config, "addr"));
b->vals[0] = json_array_get(vals, 0);
+ json_incref(b->vals[0]);
b->vals[1] = json_array_get(vals, 1);
+ json_incref(b->vals[1]);
b->u = can_register_alloc(b, bean_can_handler, "bean[%s]", b->name);
b->u->json = bean_json_handler;
diff --git a/cethcan/main.c b/cethcan/main.c
index 99a32c5..a870ca2 100644
--- a/cethcan/main.c
+++ b/cethcan/main.c
@@ -77,6 +77,8 @@ int main(int argc, char **argv)
http_init();
+ json_decref(config);
+
event_base_loop(ev_base, 0);
return 0;
}
diff --git a/cethcan/rpc.c b/cethcan/rpc.c
index fa11ecc..bfe6026 100644
--- a/cethcan/rpc.c
+++ b/cethcan/rpc.c
@@ -109,8 +109,10 @@ void rpc_perform(struct evbuffer *request,
/* TODO: asynchronous calls */
char *output = jsonrpc_handler(NULL, data, len, method_table);
- if (output)
+ if (output) {
evbuffer_add(outbuf, output, strlen(output));
+ free(output);
+ }
response_handler(handler_arg, outbuf);
evbuffer_free(outbuf);
}