leaked_allocation
Finds a local holding inferred owned storage that is never freed, returned or handed on.
Category pedantic, allow by default.
Off by default; the example is shown with the rule enabled.
#import "Basic";
Parser :: struct {
depth: int;
}
main :: () {
parser := New(Parser);
parser.depth = 3;
if parser.depth > 2 print("deep\n");
}warning[leaked_allocation]: `parser` holds memory from `New` that is never freed, returned or handed on
--> example.jai:8:5
|
8 | parser := New(Parser);
| ^^^^^^
|
help: free it when done, for example `defer free(parser);` right after this line
|
9 + defer free(parser);
|#import "Basic";
Parser :: struct {
depth: int;
}
main :: () {
parser := New(Parser);
defer free(parser);
parser.depth = 3;
if parser.depth > 2 print("deep\n");
}Off by default: ownership conventions differ, and a program that allocates once for its whole run may leak on purpose.