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

fix: don't call alloc with a length of 0 #1027

Merged
merged 2 commits into from
Jan 4, 2025

Conversation

nathanwhit
Copy link
Member

@nathanwhit nathanwhit commented Jan 4, 2025

Ref denoland/deno#27545.

Fixes a leak in deno.serve with an empty response. We would call to_string_ptr with an empty string and then call alloc with a length of 0 which is UB.

Instead of using alloc directly, which has a large number of invariants to uphold, I've changed to just use Vec APIs. That leaves us with fewer invariants to uphold, handles the tricky cases for us, and we need to make a Vec eventually anyway (since String just wraps a Vec).

@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 70.00000% with 6 lines in your changes missing coverage. Please review.

Project coverage is 81.89%. Comparing base (0c7f83e) to head (a523dc1).
Report is 216 commits behind head on main.

Files with missing lines Patch % Lines
core/runtime/ops.rs 70.00% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1027      +/-   ##
==========================================
+ Coverage   81.43%   81.89%   +0.45%     
==========================================
  Files          97      103       +6     
  Lines       23877    27811    +3934     
==========================================
+ Hits        19445    22775    +3330     
- Misses       4432     5036     +604     

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

Copy link
Member

@littledivy littledivy left a comment

Choose a reason for hiding this comment

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

LGTM

@nathanwhit nathanwhit merged commit 726b802 into denoland:main Jan 4, 2025
18 checks passed
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