diff nodejs/X_supp_njs.c @ 554:4caf6090825f Android_Skia

Fix leaking on freeing a njs runtime object
author Thinker K.F. Li <thinker@branda.to>
date Sun, 06 Jun 2010 14:15:25 +0800
parents 0a77b88500bf
children c9d23f7279a4
line wrap: on
line diff
--- 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;