Move a state onto the deferred-free list (caller holds projects_lock). * The state may still be referenced by a poll_once snapshot; poll_once * drains the list at the start of its next cycle. Returns false when * growing the list fails (OOM): the state is left untouched and the * caller must keep it registered — freeing it immediately here could be * a use-after-free against an in-flight poll
| 951 | * caller must keep it registered — freeing it immediately here could be |
| 952 | * a use-after-free against an in-flight poll snapshot. */ |
| 953 | static bool defer_state_free(cbm_watcher_t *w, project_state_t *s) { |
| 954 | if (w->pending_free_count >= w->pending_free_cap) { |
| 955 | int new_cap = w->pending_free_cap ? w->pending_free_cap * 2 : 8; |
| 956 | project_state_t **tmp = |
| 957 | realloc(w->pending_free, (size_t)new_cap * sizeof(project_state_t *)); |
| 958 | if (!tmp) { |
| 959 | cbm_log_warn("watcher.unwatch.oom", "project", s->project_name); |
| 960 | return false; |
| 961 | } |
| 962 | w->pending_free = tmp; |
| 963 | w->pending_free_cap = new_cap; |
| 964 | } |
| 965 | w->pending_free[w->pending_free_count++] = s; |
| 966 | return true; |
| 967 | } |
| 968 | |
| 969 | /* ── Stale-root pruning (#286) ──────────────────────────────────── */ |
| 970 |
no outgoing calls
no test coverage detected