Skip to content
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

Leak fix #48

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Leak fix #48

wants to merge 3 commits into from

Conversation

denizzzka
Copy link

I think this is the reason of crashes:

clang_disposeIndex() - Destroy the given index.

The index must not be destroyed until all of the translation units created within that index have been destroyed.

@denizzzka denizzzka changed the title Potential crash fix Leak fix Jun 21, 2024
@denizzzka denizzzka marked this pull request as draft June 22, 2024 14:48
@denizzzka denizzzka marked this pull request as ready for review June 23, 2024 00:01
@denizzzka denizzzka marked this pull request as draft June 23, 2024 11:14
@denizzzka
Copy link
Author

denizzzka commented Jun 23, 2024

TranslationUnit pointer stored inside of each Cursor struct to avoid destruction before cursors using it destroyed. To avoid giant changes for Cursor interface TranslationUnit pointer bypassed to each Cursor inside of unused variable CXTranslationUnitImpl.CommentToXML

Tested with ~master dpp

@denizzzka denizzzka marked this pull request as ready for review June 23, 2024 15:56
@@ -69,7 +69,16 @@ alias CXIndex = void*;
/**
* \brief A single translation unit, which resides in an index.
*/
struct CXTranslationUnitImpl;
struct CXTranslationUnitImpl {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang from 14 to at least 19 uses same struct

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need the definition of it though?

Copy link
Author

@denizzzka denizzzka Jun 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To hide store pointer to the TranslationUnit inside of one of the unused fields (CommentToXML), so that this pointer is accessible to any cursor created from CXTranslationUnit

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other ways involve massive Cursor interface changes

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We would change the interface of a type that's from libclang??

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is that?

As I remember, Cursor becomes mutable and it is leads to changes in almost all functions what use Cursor

Copy link
Contributor

@aminya aminya Jul 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be counter productive to mark code with opaque memory leaks as safe.
Regarding the supported version, that can be easily resolved by bumping the major version. There's no point in supporting old libclang libraries.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be counter productive to mark code with opaque memory leaks as safe.

This is a reason for another PR, there is no need to clutter this PR

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant that it's better to rely on the definition to fix the memory leaks instead of trying to keep the library compatible with older versions of libclang.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of trying to keep the library compatible with older versions of libclang.

I don't have such a goal - I'm only worried about the interface changes that affect dpp (it heavy uses libclang)

@@ -69,7 +69,16 @@ alias CXIndex = void*;
/**
* \brief A single translation unit, which resides in an index.
*/
struct CXTranslationUnitImpl;
struct CXTranslationUnitImpl {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need the definition of it though?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants