Permalink
Browse files

Add release_sexp_cache() to help valgrind out; call it on EOF

  • Loading branch information...
1 parent 66c19fe commit ef32c01e674d305d8e744f4c93e21e0f89b71e93 @tonyg committed Dec 30, 2010
Showing with 28 additions and 0 deletions.
  1. +15 −0 main.c
  2. +11 −0 sexp.c
  3. +2 −0 sexp.h
View
15 main.c
@@ -37,13 +37,28 @@ static void init_factory(void) {
bind_node(cmsg_cstring_bytes("factory"), new_node(&factory_class, NULL));
}
+static void console_listener(void *arg) {
+ IOHandle *in_handle = new_iohandle(0);
+ while (1) {
+ cmsg_bytes_t buf = iohandle_readwait(in_handle, 1);
+ if (in_handle->error_kind) break;
+ iohandle_drain(in_handle, buf.len);
+ }
+ delete_iohandle(in_handle);
+ interrupt_harness();
+}
+
int main(int argc, char *argv[]) {
info("cmsg, Copyright (C) 2010 Tony Garnock-Jones. All rights reserved.\n");
event_init();
info("Using libevent version %s\n", event_get_version());
init_node();
init_factory();
+ spawn(console_listener, NULL);
start_net(5671);
boot_harness();
+#ifndef NDEBUG
+ release_sexp_cache();
+#endif
return 0;
}
View
11 sexp.c
@@ -10,6 +10,17 @@
static sexp_t *freelist = NULL;
+void release_sexp_cache(void) {
+ int count = 0;
+ while (freelist != NULL) {
+ sexp_t *x = freelist;
+ freelist = x->data.pair.tail;
+ free(x);
+ count++;
+ }
+ info("Released %d cached sexp shells.\n", count);
+}
+
static inline sexp_t *alloc_shell(sexp_type_t kind) {
sexp_t *x = freelist;
if (x == NULL) {
View
2 sexp.h
@@ -30,6 +30,8 @@ typedef struct sexp_t_ {
} data;
} sexp_t;
+extern void release_sexp_cache(void);
+
extern void sexp_data_destructor(sexp_data_t *data);
extern void sexp_destructor(sexp_t *x);

0 comments on commit ef32c01

Please sign in to comment.