Fix libcurl initialization and cleanup lifecycle#104
Merged
Conversation
Two early returns (LCD open failure and OLED begin failure) executed after a successful curl_global_init but before curl_global_cleanup, violating libcurl's documented API contract. Fix each path: - LCD failure: call curl_global_cleanup() before return - OLED failure: close lcdFd then call curl_global_cleanup() before return Also adds the missing trailing newline at end of file. https://claude.ai/code/session_01K8T7AyJxjWzqrg8PfNxDVi
…alls curl_global_cleanup() was placed after while(true), making it unreachable dead code, with manual copies only in the two early-return error paths. Register it with std::atexit() immediately after a successful curl_global_init() so cleanup runs on every exit path (early returns, normal exit, exit() from signal handling) without requiring each return site to remember to call it. https://claude.ai/code/session_01Lq2gNbRv9voqav7jsmQMnD
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #72
curl_global_init()was not being called before any libcurl use. On some Raspberry Pi libcurl builds the implicit internal init insidecurl_easy_init()is skipped, leaving SSL state uninitialised — causing every weather fetch to silently fail and every alert email to be silently dropped. Additionally,curl_global_cleanup()was only reachable at the unreachable end ofmain()and was missing from early-exit paths.Changes
src/main.cpp: callcurl_global_init(CURL_GLOBAL_DEFAULT)at startup; registercurl_global_cleanupviastd::atexit()so it runs on all exit paths; close LCD fd before returning on OLED init failure.gitignore: adda.outTest plan