Skip to content

Fix leak in pysec_children and pysec_subtree.#3255

Merged
1uc merged 4 commits into
masterfrom
1uc/fix-leak-pysec
Dec 2, 2024
Merged

Fix leak in pysec_children and pysec_subtree.#3255
1uc merged 4 commits into
masterfrom
1uc/fix-leak-pysec

Conversation

@1uc

@1uc 1uc commented Nov 27, 2024

Copy link
Copy Markdown
Collaborator

The leak happens when an error occurs in the *1 helper functions. In
that case the sl (created in the top-level function under the name result)
isn't DECREFed, and also not returned. Therefore, it's leaked.

In the first case this is fixed by inlining the helper function.

In the second case, we check if the helper returns a nullptr and if not
we return the new reference to the newly created list (by using
release().ptr()). Note, that on the error path the sl will be
cleaned up due to RAII semantics.

1uc added 4 commits November 27, 2024 13:39
The leak happens when and error occurs in the `*1` "helper" function. In
that case the `sl` (created in the top-level function) isn't DECREFed,
and also not returned. Therefore, it's leaked.

In the first case this is fixed by inlining the helper function.

In the second case, we check if the helper returns a nullptr and if not
we return the new reference to the newly created list (by using
`release().ptr()`). Note, that on the error path the `sl` will be
cleaned up due to RAII semantics.
@sonarqubecloud

Copy link
Copy Markdown

@1uc 1uc marked this pull request as ready for review November 27, 2024 13:17
@codecov

codecov Bot commented Nov 27, 2024

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 47.61905% with 11 lines in your changes missing coverage. Please review.

Project coverage is 67.09%. Comparing base (bd89877) to head (804b8fd).
Report is 6 commits behind head on master.

Files with missing lines Patch % Lines
src/nrnpython/nrnpy_nrn.cpp 47.61% 11 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3255      +/-   ##
==========================================
+ Coverage   67.07%   67.09%   +0.01%     
==========================================
  Files         570      570              
  Lines      111066   111069       +3     
==========================================
+ Hits        74502    74517      +15     
+ Misses      36564    36552      -12     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@azure-pipelines

Copy link
Copy Markdown

✔️ 804b8fd -> Azure artifacts URL

@1uc 1uc merged commit 4ec288b into master Dec 2, 2024
@1uc 1uc deleted the 1uc/fix-leak-pysec branch December 2, 2024 12:01
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