Practice ยท 2 of 4
Leak Arithmetic
Implement a model of a function's allocation paths and predict balance:
``c
/* ops string: 'A' = allocate (success), 'a' = allocate (FAILED),
'F' = free, 'R' = early return on this path.
For ONE path (prefix up to 'R', or whole string if no 'R'):
return 1 if the path is balanced (no leak), 0 if it leaks. */
int path_leaks(const char *ops);
``
An allocation that failed ('a') needs no free. An allocation that succeeded
('A') must be freed ('F') before the path ends. NULL/empty: balanced (1).
Difficulty: intermediate
Press Submit to check your solution.
Back to lesson: Practice: Ownership Patterns Gym