Commit 54a8377
committed
Fix event handler leak in ExecuteLocal by unregistering handlers on cleanup
ExecuteLocal registers 6 event handlers in execute() but never
unregisters them when the process exits. This causes a memory leak
proportional to the number of processes launched over the lifetime of
a LaunchService, as the handlers and all objects they reference remain
in context._event_handlers indefinitely.
This change:
- Stores registered event handlers and context as instance variables
- Adds __unregister_event_handlers() helper that safely removes all
handlers registered by this action
- Unregisters handlers in __flush_buffers/__flush_cached_buffers after
all ProcessExited handlers (including on_exit) have fired
- Unregisters handlers when process fails to start (no ProcessExited)
- Fixes _shutdown_process() deferred handler accumulation by tracking
and replacing the OnProcessStart handler instead of creating new ones
- Adds tests verifying handler cleanup and stability during respawn
Fixes #565
Signed-off-by: Koki Shinjo <kshinjo@pfrobotics.jp>1 parent 84935de commit 54a8377
2 files changed
Lines changed: 142 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| 47 | + | |
47 | 48 | | |
48 | 49 | | |
49 | 50 | | |
| |||
223 | 224 | | |
224 | 225 | | |
225 | 226 | | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
226 | 230 | | |
227 | 231 | | |
228 | 232 | | |
| |||
283 | 287 | | |
284 | 288 | | |
285 | 289 | | |
286 | | - | |
287 | | - | |
288 | | - | |
289 | | - | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
290 | 300 | | |
291 | 301 | | |
292 | 302 | | |
| |||
413 | 423 | | |
414 | 424 | | |
415 | 425 | | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
416 | 433 | | |
417 | 434 | | |
418 | 435 | | |
| |||
442 | 459 | | |
443 | 460 | | |
444 | 461 | | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
445 | 466 | | |
446 | 467 | | |
447 | 468 | | |
| |||
504 | 525 | | |
505 | 526 | | |
506 | 527 | | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
507 | 546 | | |
508 | 547 | | |
509 | 548 | | |
| |||
514 | 553 | | |
515 | 554 | | |
516 | 555 | | |
| 556 | + | |
| 557 | + | |
517 | 558 | | |
518 | 559 | | |
519 | 560 | | |
| |||
583 | 624 | | |
584 | 625 | | |
585 | 626 | | |
| 627 | + | |
| 628 | + | |
586 | 629 | | |
587 | 630 | | |
588 | 631 | | |
| |||
703 | 746 | | |
704 | 747 | | |
705 | 748 | | |
| 749 | + | |
| 750 | + | |
706 | 751 | | |
707 | 752 | | |
708 | 753 | | |
| |||
720 | 765 | | |
721 | 766 | | |
722 | 767 | | |
723 | | - | |
724 | | - | |
| 768 | + | |
725 | 769 | | |
726 | 770 | | |
727 | 771 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
178 | 178 | | |
179 | 179 | | |
180 | 180 | | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
0 commit comments