Commit 43b696d
janus: fix pkg memory leaks in cJSON_Print/cJSON_Parse paths
The janus module uses cJSON_InitHooks() to route all cJSON allocations
through OpenSIPS pkg_malloc. Three call sites had missing cleanup:
- janus_ipc_send_request(): cJSON_Print() result was copied to shm via
shm_nt_str_dup() but the pkg-allocated original was never freed.
Also added a NULL check -- under pkg exhaustion cJSON_Print returns
NULL and the subsequent strlen(NULL) causes a crash.
- w_janus_send_request(): the cJSON tree from cJSON_Parse() was passed
to janus_ipc_send_request() (which serializes it to shm) but
cJSON_Delete() was never called afterward. Also added cleanup on the
get_janus_connection_by_id() failure path.
- janus_raise_event() and handle_janus_json_request(): added NULL
checks after cJSON_Print(). Fixed missing pkg_free(full_json) on
the shm_strdup() failure path in handle_janus_json_request().
Together these leak ~350 bytes of pkg memory per janus_send_request()
call, leading to SIP worker pkg exhaustion and crash under sustained
load.
Fixes #37121 parent b25788d commit 43b696d
3 files changed
Lines changed: 20 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
112 | 112 | | |
113 | 113 | | |
114 | 114 | | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
115 | 119 | | |
116 | 120 | | |
117 | 121 | | |
| |||
191 | 195 | | |
192 | 196 | | |
193 | 197 | | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
194 | 202 | | |
195 | 203 | | |
196 | 204 | | |
197 | 205 | | |
| 206 | + | |
198 | 207 | | |
199 | 208 | | |
200 | 209 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
208 | 208 | | |
209 | 209 | | |
210 | 210 | | |
| 211 | + | |
211 | 212 | | |
212 | 213 | | |
213 | 214 | | |
214 | 215 | | |
215 | 216 | | |
216 | 217 | | |
| 218 | + | |
217 | 219 | | |
218 | 220 | | |
219 | 221 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
282 | 282 | | |
283 | 283 | | |
284 | 284 | | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
285 | 290 | | |
286 | 291 | | |
287 | 292 | | |
| 293 | + | |
288 | 294 | | |
289 | 295 | | |
290 | 296 | | |
291 | 297 | | |
292 | 298 | | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
293 | 302 | | |
294 | 303 | | |
295 | 304 | | |
| |||
0 commit comments