8000
Skip to content

[captive_portal] Use stack buffer for IP address logging in DNS server - #12679

Merged
bdraco merged 1 commit into
devfrom
no_heap_alloc_start_dnsserver
Jan 3, 2026
Merged

[captive_portal] Use stack buffer for IP address logging in DNS server#12679
bdraco merged 1 commit into
devfrom
no_heap_alloc_start_dnsserver

Conversation

@bdraco
@bdraco bdraco commented Dec 27, 2025
Copy link
Copy Markdown
Member

What does this implement/fix?

Eliminates heap allocation during DNS server startup logging by using a stack buffer with str_to() instead of ip.str().c_str() which creates a temporary std::string.

The buffer and log statement are guarded with #if ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_VERBOSE to avoid unused variable warnings when verbose logging is disabled.

This one doesn't matter so much but its in a place where someone might copy this pattern so good to fix since I noticed it.

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Developer breaking change (an API change that could break external components)
  • Code quality improvements to existing code or addition of tests
  • Other

Related issue or feature (if applicable):

  • n/a

Pull request in esphome-docs with documentation (if applicable):

  • n/a

Test Environment

  • ESP32
  • ESP32 IDF
  • ESP8266
  • RP2040
  • BK72xx
  • RTL87xx
  • nRF52840

Example entry for config.yaml:

captive_portal:

Checklist:

  • The code change is tested and works locally.
  • Tests have been added to verify that the new code works (under tests/ folder).

If user exposed functionality or configuration variables are added/changed:

Copilot AI review requested due to automatic review settings December 27, 2025 19:08
@bdraco
bdraco requested a review from a team as a code owner December 27, 2025 19:08
@github-actions
Copy link
Copy Markdown
Contributor

To use the changes from this PR as an external component, add the following to your ESPHome configuration YAML file:

external_components:
  - source: github://pr#12679
    components: [captive_portal]
    refresh: 1h

(Added by the PR bot)

@github-actions
Copy link
Copy Markdown
Contributor

👋 Hi there! This PR modifies 1 file(s) with codeowners.

@esphome/core - As codeowner(s) of the affected files, your review would be appreciated! 🙏

Note: Automatic review request may have failed, but you're still welcome to review.

Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR eliminates heap allocation during DNS server startup logging by replacing ip.str().c_str() (which creates a temporary std::string) with a stack-allocated buffer and the str_to() method. The change is guarded with a preprocessor directive to prevent unused variable warnings when verbose logging is disabled.

  • Replaces heap allocation with stack buffer for IP address logging in DNS server
  • Guards the buffer and log statement with #if ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_VERBOSE
  • Uses the existing network::IP_ADDRESS_BUFFER_SIZE constant (40 bytes) and str_to() method

@codecov-commenter
codecov-commenter commented Dec 27, 2025
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 73.34%. Comparing base (5e99dd1) to head (0b621bb).

Additional details and impacted files
@@            Coverage Diff             @@
##              dev   #12679      +/-   ##
==========================================
- Coverage   73.36%   73.34%   -0.03%     
==========================================
  Files          53       53              
  Lines       11283    11283              
  Branches     1532     1532              
==========================================
- Hits         8278     8275       -3     
- Misses       2605     2607       +2     
- Partials      400      401       +1     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions
Copy link
Copy Markdown
Contributor

Memory Impact Analysis

Components: captive_portal
Platform: esp32-idf

Metric Target Branch This PR Change
RAM 33,776 bytes 33,776 bytes ➡️ +0 bytes (0.00%)
Flash 717,459 bytes 717,459 bytes ➡️ +0 bytes (0.00%)

Note: This analysis measures static RAM and Flash usage only (compile-time allocation).
Dynamic memory (heap) cannot be measured automatically.
⚠️ You must test this PR on a real device to measure free heap and ensure no runtime memory issues.

This analysis runs automatically when components change. Memory usage is measured from a representative test configuration.

@bdraco
bdraco commented Jan 3, 2026
Copy link
Copy Markdown
Member Author

Thanks

@bdraco
bdraco merged commit ddb6c6c into dev Jan 3, 2026
42 checks passed
@bdraco
bdraco deleted the no_heap_alloc_start_dnsserver branch January 3, 2026 00:14
@github-actions github-actions Bot locked and limited conversation to collaborators Jan 4, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

0