You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The code was acting like this before:
1. Allocate a new `Vec<LLVMValueRef>`,
2. Get a mutable pointer to it,
3. Forget the vector,
4. Fill the vector with `LLVMGetMDNodeOperands`,
5. Read back the vector as a slice,
6. Map slice values, and collect them in a newly allocated vector.
Here, the first vector is lost. That's a memory leak.
This patch changes the step 5: Instead of reading the results as a
slice, results are read as a vector, the same vector, with the same
pointer. That way, the new `vec` vector will be dropped by Rust
nicely.
Compiling and running the documentation of the
`Module::get_global_metadata` method, valgrind gives us the following
results:
(before)
```
==35805== LEAK SUMMARY:
==35805== definitely lost: 24 bytes in 2 blocks
==35805== indirectly lost: 0 bytes in 0 blocks
==35805== possibly lost: 0 bytes in 0 blocks
==35805== still reachable: 145 bytes in 1 blocks
==35805== suppressed: 137,663 bytes in 1,484 blocks
```
(after)
```
==37629== LEAK SUMMARY:
==37629== definitely lost: 16 bytes in 1 blocks
==37629== indirectly lost: 0 bytes in 0 blocks
==37629== possibly lost: 0 bytes in 0 blocks
==37629== still reachable: 145 bytes in 1 blocks
==37629== suppressed: 137,663 bytes in 1,484 blocks
```
0 commit comments