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

Potential memory leak #42

Open
dipterix opened this issue May 28, 2024 · 0 comments
Open

Potential memory leak #42

dipterix opened this issue May 28, 2024 · 0 comments

Comments

@dipterix
Copy link
Contributor

dipterix commented May 28, 2024

Hi @zarquon42b

I was testing my code with valgrind and it led me to the following code:

Rvcg/src/Rdijkstra.cpp

Lines 96 to 99 in a7c34a5

MyMesh::PerVertexAttributeHandle<VertexPointer> sourcesHandle;
sourcesHandle = tri::Allocator<MyMesh>::AddPerVertexAttribute<MyMesh::VertexPointer> (m, "sources");
MyMesh::PerVertexAttributeHandle<VertexPointer> parentHandle;
parentHandle = tri::Allocator<MyMesh>::AddPerVertexAttribute<MyMesh::VertexPointer> (m, "parent");

I wonder should AddPerVertexAttribute be used with DeletePerVertexAttribute together?

https://vcg.isti.cnr.it/vcglib/attributes.html states that:

Remember that the scope of a handle does not interfere with the memory allocation of the attribute. If you do not delete an attribute explicitly, it will stay allocated until the mesh itself is destroyed, even if you do not have any more handles to it.

Also the following code may segfault when the path does not exist (not connected)

Rvcg/src/Rdijkstra.cpp

Lines 117 to 121 in a7c34a5

while(current_vertex != source) {
MyMesh::VertexPointer parent = parentHandle[current_vertex];
int next_vertex = indices[parent];
current_vertex = next_vertex;
path.push_back(current_vertex + 1);

When the segfault happens, parent will be NULL, hence indexing indices[parent] will crash the process.

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

No branches or pull requests

1 participant