Commit dc53fb7
committed
Fix: Memory leak in CurrentUser.getCurrentUser()
Fixed memory leak where an UnsafeMutablePointer<passwd> was allocated
but never deallocated.
Issue Analysis:
- Line 43 was allocating heap memory for `result` pointer
- getpwuid_r() immediately overwrites `result` to point to `pwd` (stack)
- The allocated heap memory was leaked on every call
- Attempting to deallocate crashed because `result` pointed to stack memory
Root Cause:
The allocation was unnecessary. getpwuid_r() expects `result` as an
output parameter - it sets the pointer itself, no pre-allocation needed.
Solution:
Removed the unnecessary .allocate(capacity: 1) call. Now `result` is
initialized as nil and getpwuid_r() sets it to point to `pwd` on success.
This function is called every time a terminal is opened, so the leak
would accumulate with each terminal session.1 parent d0d2893 commit dc53fb7
1 file changed
+2
-2
lines changedLines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
42 | | - | |
43 | | - | |
| 42 | + | |
| 43 | + | |
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| |||
0 commit comments