Skip to content

Fix libcurl initialization and cleanup lifecycle#104

Merged
GageLawton merged 3 commits into
mainfrom
claude/fix-curl-global-init-72
May 27, 2026
Merged

Fix libcurl initialization and cleanup lifecycle#104
GageLawton merged 3 commits into
mainfrom
claude/fix-curl-global-init-72

Conversation

@GageLawton
Copy link
Copy Markdown
Owner

Summary

Closes #72

curl_global_init() was not being called before any libcurl use. On some Raspberry Pi libcurl builds the implicit internal init inside curl_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 of main() and was missing from early-exit paths.

Changes

  • src/main.cpp: call curl_global_init(CURL_GLOBAL_DEFAULT) at startup; register curl_global_cleanup via std::atexit() so it runs on all exit paths; close LCD fd before returning on OLED init failure
  • .gitignore: add a.out

Test plan

  • Confirm weather fetches succeed on a Pi where libcurl's implicit init was previously unreliable
  • Verify the process exits cleanly when OLED init fails

claude added 3 commits May 25, 2026 04:14
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
@GageLawton GageLawton merged commit 959ef18 into main May 27, 2026
2 checks passed
@GageLawton GageLawton deleted the claude/fix-curl-global-init-72 branch May 27, 2026 01:28
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.

Bug: curl_global_init() is never called; libcurl SSL state undefined on some platforms

2 participants