Skip to content

Conversation

Nao-ris
Copy link
Contributor

@Nao-ris Nao-ris commented Mar 11, 2025

The Test Gh workflow is enhanced by also running the whole test suite with the LEAK_CHECK environment variable.
While testing this functionality, it became apparent that we had memory leaks on CBLCollection, CBLScope & CBLQueryIndex objects.

The functions retain and wrap were not clear enough on what they did, especially with the doc comments that were inverted. So the changes are:

  1. Rename retain to reference
  2. Rename wrap to take_ownership
  3. Fix the doc comments on all functions
  4. Fix the cases where retain and wrap were misused for CBLCollection, CBLScope & CBLQueryIndex
  5. Implement Drop for QueryIndex

The tests are now passing with the LEAK_CHECK environment variable.

Additional changes:

  • The README is improved to document how to test
  • The README is improved to make editions (community & enterprise) more understandable
  • The file src/main.rs is deleted as this is a library

@Nao-ris Nao-ris changed the title Cleanup README Improve README & Fix memory leaks Mar 12, 2025
@Nao-ris Nao-ris changed the title Improve README & Fix memory leaks Fix memory leaks & Improve README Mar 12, 2025
@Nao-ris Nao-ris marked this pull request as ready for review March 12, 2025 11:07
@Nao-ris Nao-ris requested a review from a team as a code owner March 12, 2025 11:07
@Nao-ris Nao-ris merged commit 97d8d9a into main Mar 24, 2025
5 checks passed
@Nao-ris Nao-ris deleted the readme_cleanup branch March 24, 2025 09:40
Nao-ris added a commit that referenced this pull request Mar 26, 2025
In PR #24 I started
removing memory leaks by checking them when the utility function
`with_db` was used in unit tests.

This PR finalizes that process.

It contains a new utility class `LeakChecker` that checks the leaks for
a unit test.
`LeakChecker` is added to the utility classes `ReplicationTwoDbsTester`
and `ReplicationThreeDbsTester`, used to test replication use cases.
`LeakChecker` is also added to all tests that do not use one of the
three utility function & classes.

Three new sources of memory leaks were discovered this time:

- in `src/encryptable.rs`, `reference` was used instead of
`take_ownership` when creating a new `Encryptable`
- in `src/replicator.rs`, the struct `Endpoint` was not implementing
`Drop`
- in `src/replicator.rs`, when a `Replicator` was created we were not
giving ownership of the `CBLDatabase` object to the
`CBLReplicatorConfiguration` object
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.

2 participants