|
|
|
|
|
by enriquto
2962 days ago
|
|
For small and moderate memory requirements, C pretty much supports RAII via variable-length arrays. You just replace this: void f(int n)
{
float *x = malloc(n * sizeof*x);
// ...
free(x);
}
with this: void f(int n)
{
float x[n];
// ...
}
edit: and you can exit your function anywhere without leaking. |
|
I just need to call your example function with the right n to corrupt the stack.