Created by: zhiqiu
As the title.
The args of InitGflags
passed from python to c++ is a vector of string, like ['--tryfromenv=check_nan_inf,fast_check_nan_inf,xxx']
.
In function InitGflags
, since ParseCommandLineFlags
takes char***
as the second input arg, the original implementation new
a char**
by:
char **arr = new char *[argv.size()];
It did not delete arr
, and may result in a smalle size memory leak
detected by some code analysis tools, such as valgrind. For example, the result of valgrind
:
It should be ponited out that the lambda function inside InitGflags
uses call_once
, so it is will not cause much memory leak indeed. The newed memory will be re-collected by os when the process exit.
But, it is still not a good code practice, since delete
is not paired with new
explictly.
When I try to add delete in the lamdda function, I got Error in python3: free(): invalid pointer:xx
. Debugging found that arr
is assigned to a new memory address instread of the original newed one.
To avoid errors, I use vector instead of newed pointer to do it safely.