-
Notifications
You must be signed in to change notification settings - Fork 632
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cxx: Memory leak for anonymous function parameters #3372
Comments
I'm also getting this leak:
but in this case I don't really know what's going on. |
What kind of input did you give to ctags? |
The first one is not reproduced with the input
|
That's a good question - basically all Geany sources, GTK, glib and all of our unit tests. But I haven't explored in detail what exactly is causing it yet. |
The
from |
@techee, thank you.
|
…ken parameter list Close universal-ctags#3372. The original code assumed tokens allocated in cxxParserTokenChainLooksLikeFunctionParameterList() for tagging anonymous parameters are deleted in its caller side. This assumption is true if the parameter list where the anonymous parameters are defined is valid. If the parameter list is broken, the tokens are never deleted. This cause a memory leak as reported in universal-ctags#3372. With this change, cxxParserTokenChainLooksLikeFunctionParameterList() releases the tokens if given parameter list is broken. Signed-off-by: Masatake YAMATO <[email protected]>
…ken parameter list Close universal-ctags#3372. The original code assumed tokens allocated in cxxParserTokenChainLooksLikeFunctionParameterList() for tagging anonymous parameters are deleted on its caller side. This assumption is true if the parameter list where the anonymous parameters are defined is valid. If the parameter list is broken, the tokens are never deleted. This cause a memory leak, as reported in universal-ctags#3372. With this change, cxxParserTokenChainLooksLikeFunctionParameterList() releases the tokens if given parameter list is broken. Signed-off-by: Masatake YAMATO <[email protected]>
I'm also getting this
for
but the code looks very similar and is probably the same leak. |
Reproduced even with ctags + #3373. I tried the input shorter: |
Close universal-ctags#3372. The original code assumed tokens allocated in cxxParserTokenChainLooksLikeFunctionParameterList() for tagging anonymous parameters were deleted on its caller side (cxxParserEmitFunctionParameterTags()). However, in some conditions, cxxParserEmitFunctionParameterTags() are not called. As the allocated tokens are not deleted, as reported in universal-ctags#3372. To avoid the memory leaking, the deletion cannot depend on cxxParserEmitFunctionParameterTags(). This change uses per-parsing trashbox for deleting the anonymous tokens. The objects linked to the trashbox are destroyed at the end of parsing current binput file. Signed-off-by: Masatake YAMATO <[email protected]>
…meters Close universal-ctags#3372. The original code assumed tokens allocated in cxxParserTokenChainLooksLikeFunctionParameterList() for tagging anonymous parameters were deleted on its caller side (cxxParserEmitFunctionParameterTags()). However, in some conditions, cxxParserEmitFunctionParameterTags() are not called. As results, the allocated tokens are not deleted. To avoid the memory leaking, the deletion cannot depend on cxxParserEmitFunctionParameterTags(). This change uses per-parsing trashbox for deleting the anonymous tokens. The objects linked to the trashbox are destroyed at the end of parsing current binput file. Signed-off-by: Masatake YAMATO <[email protected]>
…meters Close universal-ctags#3372. The original code assumed tokens allocated in cxxParserTokenChainLooksLikeFunctionParameterList() for tagging anonymous parameters were deleted on its caller side (cxxParserEmitFunctionParameterTags()). However, in some conditions, cxxParserEmitFunctionParameterTags() are not called. As results, the allocated tokens are not deleted. To avoid the memory leaking, the deletion cannot depend on cxxParserEmitFunctionParameterTags(). This change uses per-parsing trashbox for deleting the anonymous tokens. The objects linked to the trashbox are destroyed at the end of parsing current input file. Signed-off-by: Masatake YAMATO <[email protected]>
…meters Close universal-ctags#3372. The original code assumed tokens allocated in cxxParserTokenChainLooksLikeFunctionParameterList() for tagging anonymous parameters were deleted on its caller side (cxxParserEmitFunctionParameterTags()). However, in some conditions, cxxParserEmitFunctionParameterTags() are not called. As a result, the allocated tokens are not deleted. To avoid the memory leaking, the deletion cannot depend on cxxParserEmitFunctionParameterTags(). This change uses per-parsing trashbox for deleting the anonymous tokens. The objects linked to the trashbox are destroyed at the end of parsing the current input file. Signed-off-by: Masatake YAMATO <[email protected]>
I made a new pull request for fixing this issue. |
…meters Partially close universal-ctags#3372. The original code assumed tokens allocated in cxxParserTokenChainLooksLikeFunctionParameterList() for tagging anonymous parameters were deleted on its caller side (cxxParserEmitFunctionParameterTags()). However, in some conditions, cxxParserEmitFunctionParameterTags() are not called. As a result, the allocated tokens are not deleted. To avoid the memory leaking, the deletion cannot depend on cxxParserEmitFunctionParameterTags(). This change uses per-parsing trashbox for deleting the anonymous tokens. The objects linked to the trashbox are destroyed at the end of parsing the current input file. Signed-off-by: Masatake YAMATO <[email protected]>
About the example input shown in the initial comment, #3375 fixes the memory leak. |
…meters Partially close universal-ctags#3372. The original code assumed tokens allocated in cxxParserTokenChainLooksLikeFunctionParameterList() for tagging anonymous parameters were deleted on its caller side (cxxParserEmitFunctionParameterTags()). However, in some conditions, cxxParserEmitFunctionParameterTags() are not called. As a result, the allocated tokens are not deleted. To avoid the memory leaking, the deletion cannot depend on cxxParserEmitFunctionParameterTags(). This change uses per-parsing trashbox for deleting the anonymous tokens. The objects linked to the trashbox are destroyed at the end of parsing the current input file. Signed-off-by: Masatake YAMATO <[email protected]>
…meters Partially close universal-ctags#3372. The original code assumed tokens allocated in cxxParserTokenChainLooksLikeFunctionParameterList() for tagging anonymous parameters were deleted on its caller side (cxxParserEmitFunctionParameterTags()). However, in some conditions, cxxParserEmitFunctionParameterTags() are not called. As a result, the allocated tokens are not deleted. To avoid the memory leaking, the deletion cannot depend on cxxParserEmitFunctionParameterTags(). This change uses per-parsing trashbox for deleting the anonymous tokens. The objects linked to the trashbox are destroyed at the end of parsing the current input file. Signed-off-by: Masatake YAMATO <[email protected]>
…meters This is a cherry-picked commit 55ba7264c0722c9519c0fdfacdf2363ad1c59e94 from uctags to address a memory leak reported in universal-ctags/ctags#3372
When I tried reproducing the leak today on Fedora36, I couldn't.
|
Can't reproduce it on Debian 11 either (previously I used Debian 10 but with the latest valgrind). Instead, I'm getting
but that seems to be like a false positive because I don't see anything wrong with the code. So maybe this issue can be closed. |
Thank you for trying. What kind of input did you give to ctags for making valgrind report the "Conditional jump or move depends on uninitialised value(s)" ? |
It was
with valgrind 3.16.1. On Debian 10 for which I reported this issue originally it was valgrind 3.19.0 compiled form sources (the shipped valgrind version didn't work correctly on my ARM-based macbook with parallels desktop linux VM). Yeah, I'm making by best not to make bugs reported by me reproducible by anyone else ;-). |
Thank you. |
When running a slightly older version of ctags (in Geany) with valgrind, I'm getting this:
This is for function parameter kinds enabled and it seems to be related to the situation when anonymous function parameter is discovered like in
void foo(int *)
. I suspect that normallypIdentifier
points to something like token chain that is released by some other code while in this case the token is created and not freed in:ctags/parsers/cxx/cxx_parser_function.c
Line 2179 in a7ae1df
The text was updated successfully, but these errors were encountered: