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 String returned from server::arg() dropping out of scope #253

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

louissobel
Copy link

Problem

the String returned by the server::arg methods (like server::arg("POWER")) drops out of scope right after its c_str() method is called.

I'm using a ESP32. That implementation (https://github.com/espressif/arduino-esp32/blob/2.0.14/libraries/WebServer/src/WebServer.cpp#L549) returns a String by value, so once the String returned by arg() is out of scope, the underlying c_str() pointer becomes invalid.

Without this fix, this was causing the web interface to not take updates — by the time the HeatPump library tried to read the various argument strings they were reset.

Fix

I'm not sure that this is a good fix, but it does work: keeping the returned String in scope until after the setSettings call ensures that the underlying char * buffers aren't cleared.

Maybe a better fix would be to update the settings interface to support a String optionally somehow?

@andrewleech
Copy link
Contributor

Oh, I missed your PR here and added a similar fix into my branch just today if you'd like to compare ideas! #248

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