Introduce __attribute__((cleanup)) for memory management. - #20
Introduce __attribute__((cleanup)) for memory management.#20kivkiv12345 wants to merge 1 commit into
Conversation
This commit makes us more dependant on GCC, but introduces a more reliable way to free optparse_t pointers. This commit also solves the following memory leaks: 2 missing calls to optparse_del() in loki.c (loki_start_cmd()) 6 missing calls to optparse_del() in slash_apm.c (apm_load_cmd(), apm_info_cmd()) 1 call to optparse_del() after return in prometheus.c (prometheus_start_cmd()) 1 missing call to optparse_del() in builtins.c (slash_builtin_watch())
|
I dont favor the gcc extension. A large portion of our code is flight code which would not accept it, so we might as well use similar pattern. The preferred pattern which is MISRA friendly is the |
|
That is a fair point, although I recall one time I helped debug undefined behavior stemming from Since making this PR, I have learned that Clang supports I recall Troels strongly prefers we don't include compiler specific extension usage in open-source libraries, a fair point. Your argument against CSH is to keep it uniform. I suspect (hope) the memory leaks mentioned in the description have been fixed since making this PR. |
This commit makes us more dependant on GCC,
but introduces a more reliable way to free optparse_t pointers.
Currently this pull request solves the following memory leaks:
2 missing calls to optparse_del() in loki.c (loki_start_cmd())
6 missing calls to optparse_del() in slash_apm.c (apm_load_cmd(), apm_info_cmd())
1 call to optparse_del() after return in prometheus.c (prometheus_start_cmd())
1 missing call to optparse_del() in builtins.c (slash_builtin_watch())
csp_init_cmd() has been spared, as we deliberately leak "parser" there to keep some string pointers.