Cleanup of memory allocation and usage of events - #21943
Conversation
6b0015c to
9fbf40f
Compare
|
@greptile review |
Greptile SummaryThis PR is a broad cleanup across ~120 files, standardising event-pointer truth tests to
Confidence Score: 4/5The PR is safe to merge. All three substantive bug fixes (sigevent NULL-deref, BMP mirror multi-queue corruption, rfapi timer leak) are correct, and the new topotest covers the BMP crash scenario. The changes are correct and the real fixes are well-motivated, but the sweep touches ~120 files across nearly every FRR daemon, which means any subtle semantic difference between The Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["bmp_mirror_packet(peer, ...)"] --> B["For each bgp_vrf in bm->bgp"]
B --> C{"bmpbgp = bmp_bgp_find(bgp_vrf)\nfound?"}
C -- No --> B
C -- Yes --> D["qitem = NULL (per-VRF local)"]
D --> E["For each bmp_targets bt with mirror=true"]
E --> F{"bgp_vrf matches\npeer->bgp?"}
F -- No --> E
F -- Yes --> G["For each bmp session"]
G --> H{"qitem == NULL?"}
H -- Yes --> I["XCALLOC new qitem\nset peerid/tv/len/data"]
I --> J["refcount++\nmirrorpos = qitem\npullwr_bump"]
H -- No --> J
J --> G
G -- done --> K{"qitem != NULL?"}
K -- No --> B
K -- Yes --> L["Add to bmpbgp->mirrorq\nbmp_mirror_cull\nupdate qsizemax"]
L --> B
B -- done --> M["return 0"]
Reviews (1): Last reviewed commit: "bgpd: Fix crash in bgp_bmp.c with a mirr..." | Re-trigger Greptile |
|
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
9fbf40f to
c177973
Compare
5a17289 to
c50d3ad
Compare
c50d3ad to
22c2d4a
Compare
There are several classes of problems: a) event pointer is set to NULL inside the handler function. This is unnecessary and redundant, so we can safely remove the set. b) event_cancel is called then the event pointer is set to NULL. Again this is redundant. c) fresh calloc call we set the event pointer to NULL. This is redundant. d) Actual bug, use malloc to grab memory and then call some event_add_XX function. The malloc'ed memory may not be null the initial event_add_XX function will safely return since it believes that the thread pointer is already there. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
ospf_apiserver.c is using XMALLOC for alloc'ing memory, switch over to XCALLOC and drop the NULL pointer assignments to event structures as well as the memset. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
We have this pattern: event = NULL event_add_timer(..., &event...); FRR code should never set a event to NULL as that any existing timer will be run but the ability to stop it has been lost, modify the code to cancel the event and then add the timer again. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
The code was using this as a pattern: event = NULL; event_add_timer(...,&event,...); This can leave a dangling event in the event system. Explicitly cancel and then restart. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
Instead of null'ing pointers, explicitly cancel the event timer as that leaving a event dangling is dangerous and causes problems. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
The event system when calling a event handler has already set the event pointer to NULL that was handed in. There is no need to do this again. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
The pattern of: if (event) event_cancel(); makes no sense, just do a `event_cancel()`. That is sufficient. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
The pattern: if (event) Should really be: if (event_is_scheduled(event)) Replace. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
XCALLOC/XMALLOC and XREALLOC cannot fail, as such checking for NULL is redundant and unnecessary, remove. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
The md_alg variable is being set 2 times, no need. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
22c2d4a to
1a1ea77
Compare
Cleanup of both memory allocation and usage of events across of FRR to make the whole thing be consistent.
a) ldpd: event cleanup of unnecessary pointer setting for events, fix bug using malloc instead of calloc
b) lib: Fix null deref in frr_signal_timer
c) ospfd: Cleanup of ospf_apiserver usage of XMALLOC to XCALLOC
d) bgpd, use event_cancel instead of NULL setting in rfapi code
e) pimd, use event_cancel instead of NULL setting.
f) zebra, use event cancel instead of NULL setting.
g) Drop redundant Null setting inside of event handlers
h) Drop redundant if guards before event_cancel calling
i) Use
event_is_scheduled()for truthiness of event being active or notj) Don't need to check for NULL when using alloc functions
k) Create a test that shows bgp bmp mirroring is broken
l) Fix broken bmp mirroring.