-
Notifications
You must be signed in to change notification settings - Fork 33
Closed
Description
Today, APIs that free memory follow the POSIX standard model for free(), etc., namely:
- The argument is the pointer to free, and
- null is permitted
In microsoft/ebpf-for-windows#2783 (comment), @gtrevi asks:
Could we merge nulling the pointer into cxplat_free_preemptible_work_item?
That is, Gianni asks about changing point 1 above, to take an [in,out] pointer to the pointer, and set it to null after freeing.
In #109, @nibanks also asks about changing point 2 above. There, Dave Thaler responded:
When we went through the decision process, we came to the opposite conclusion (ALL free apis should accept nullptr), for mainly the following reasons:
- Consistency with the POSIX standard. This is the industry consensus on good API design, which is why free() is defined to accept a null ptr. Thus, programmers familiar with standard API conventions aren't surprised.
- Minimizes number of code paths (reducing code complexity and increasing code coverage), since otherwise many places, instead of 1, have to test for null.
The first point applies to Gianni's question as well.
Metadata
Metadata
Assignees
Labels
No labels