# HG changeset patch # User Thinker K.F. Li # Date 1275804925 -28800 # Node ID 4caf6090825f8daf91b120386896fd6a0902fd8a # Parent 0a77b88500bf9dc47ccdb53c23d859465c94f0ae Fix leaking on freeing a njs runtime object diff -r 0a77b88500bf -r 4caf6090825f nodejs/X_supp_njs.c --- a/nodejs/X_supp_njs.c Sun Jun 06 14:11:13 2010 +0800 +++ b/nodejs/X_supp_njs.c Sun Jun 06 14:15:25 2010 +0800 @@ -18,6 +18,7 @@ typedef struct _njs_runtime { ev_io iowatcher; ev_timer tmwatcher; + int enable_io; int enable_timer; void *xrt; } njs_runtime_t; @@ -100,6 +101,7 @@ fd = _X_MB_get_x_conn_for_nodejs(xrt); ev_io_init(&rt->iowatcher, x_conn_cb, fd, EV_READ); ev_io_start(&rt->iowatcher); + rt->enable_io = 1; set_next_timeout(rt); } @@ -111,9 +113,13 @@ /* * stop IO and timer watcher */ - ev_io_stop(&rt->iowatcher); + if(rt->enable_io) + ev_io_stop(&rt->iowatcher); if(rt->enable_timer) ev_timer_stop(&rt->tmwatcher); + + X_MB_free(rt->xrt); + free(rt); } njs_runtime_t * @@ -127,6 +133,7 @@ xrt = X_MB_new(display_name, w, h); rt->xrt = xrt; + rt->enable_io = 0; rt->enable_timer = 0; /* no timer, now */ return rt;