Mercurial > MadButterfly
comparison 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 |
comparison
equal
deleted
inserted
replaced
553:0a77b88500bf | 554:4caf6090825f |
---|---|
16 #endif | 16 #endif |
17 | 17 |
18 typedef struct _njs_runtime { | 18 typedef struct _njs_runtime { |
19 ev_io iowatcher; | 19 ev_io iowatcher; |
20 ev_timer tmwatcher; | 20 ev_timer tmwatcher; |
21 int enable_io; | |
21 int enable_timer; | 22 int enable_timer; |
22 void *xrt; | 23 void *xrt; |
23 } njs_runtime_t; | 24 } njs_runtime_t; |
24 | 25 |
25 static void timer_cb(EV_P_ ev_timer *tmwatcher, int revent); | 26 static void timer_cb(EV_P_ ev_timer *tmwatcher, int revent); |
98 * Setup watcher for X connection. | 99 * Setup watcher for X connection. |
99 */ | 100 */ |
100 fd = _X_MB_get_x_conn_for_nodejs(xrt); | 101 fd = _X_MB_get_x_conn_for_nodejs(xrt); |
101 ev_io_init(&rt->iowatcher, x_conn_cb, fd, EV_READ); | 102 ev_io_init(&rt->iowatcher, x_conn_cb, fd, EV_READ); |
102 ev_io_start(&rt->iowatcher); | 103 ev_io_start(&rt->iowatcher); |
104 rt->enable_io = 1; | |
103 | 105 |
104 set_next_timeout(rt); | 106 set_next_timeout(rt); |
105 } | 107 } |
106 | 108 |
107 /*! \brief Free njs_runtime_t. | 109 /*! \brief Free njs_runtime_t. |
109 void | 111 void |
110 X_njs_MB_free(njs_runtime_t *rt) { | 112 X_njs_MB_free(njs_runtime_t *rt) { |
111 /* | 113 /* |
112 * stop IO and timer watcher | 114 * stop IO and timer watcher |
113 */ | 115 */ |
114 ev_io_stop(&rt->iowatcher); | 116 if(rt->enable_io) |
117 ev_io_stop(&rt->iowatcher); | |
115 if(rt->enable_timer) | 118 if(rt->enable_timer) |
116 ev_timer_stop(&rt->tmwatcher); | 119 ev_timer_stop(&rt->tmwatcher); |
120 | |
121 X_MB_free(rt->xrt); | |
122 free(rt); | |
117 } | 123 } |
118 | 124 |
119 njs_runtime_t * | 125 njs_runtime_t * |
120 X_njs_MB_new(char *display_name, int w, int h) { | 126 X_njs_MB_new(char *display_name, int w, int h) { |
121 njs_runtime_t *rt; | 127 njs_runtime_t *rt; |
125 ASSERT(rt != NULL); | 131 ASSERT(rt != NULL); |
126 | 132 |
127 xrt = X_MB_new(display_name, w, h); | 133 xrt = X_MB_new(display_name, w, h); |
128 | 134 |
129 rt->xrt = xrt; | 135 rt->xrt = xrt; |
136 rt->enable_io = 0; | |
130 rt->enable_timer = 0; /* no timer, now */ | 137 rt->enable_timer = 0; /* no timer, now */ |
131 | 138 |
132 return rt; | 139 return rt; |
133 } | 140 } |
134 | 141 |