Skip to content

Fix #12203: return NULL after flb_worker_context_create failure in flb_log_create - #12274

Open
MsfPablo wants to merge 1 commit into
fluent:masterfrom
MsfPablo:fix-12203
Open

Fix #12203: return NULL after flb_worker_context_create failure in flb_log_create#12274
MsfPablo wants to merge 1 commit into
fluent:masterfrom
MsfPablo:fix-12203

Conversation

@MsfPablo

@MsfPablo MsfPablo commented Aug 12, 2026

Copy link
Copy Markdown

Fixes #12203

When flb_worker_context_create() fails inside flb_log_create(), the
existing code destroyed log->evl, freed log, set config->log = NULL,
but then continued execution. The subsequent flb_log_worker_init(worker)
call receives worker == NULL and either dereferences NULL (when the cache
is created) or reads the freed log->evl (when cache creation also fails).

Add return NULL; immediately after the cleanup so the rest of the function
is reachable only when both log and worker are valid.

Severity: Low — OOM-only availability bug.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Fixed an error-handling issue that could cause log creation to continue unexpectedly when worker-context setup fails.
    • Ensured a clear failure result is returned after cleanup.

… in flb_log_create

When flb_worker_context_create() returns NULL, flb_log_create() freed log
and continued execution, leading to a NULL deref in flb_log_worker_init() and
a use-after-free when log_cache creation failed. Return NULL immediately
after cleanup so the rest of the function is only reached when both log
and worker are valid.

Co-Authored-By: Claude <noreply@anthropic.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5df14a02e2

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/flb_log.c
mk_event_loop_destroy(log->evl);
flb_free(log);
config->log = NULL;
return NULL;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Release logger resources before returning on worker failure

When flb_worker_context_create() fails after the logger pipe, metrics, mutexes, and possibly the file sink have already been initialized, this new return NULL leaves those resources behind and clears config->log, so later flb_config_exit() cannot call flb_log_destroy() to clean them up. In startup or embedded callers that retry after a transient allocation failure, each failed attempt leaks the pipe descriptors, cmetrics state, and an open log file when FLB_LOG_FILE was selected; this failure path should mirror the relevant pre-thread cleanup before returning.

Useful? React with 👍 / 👎.

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.

^ @MsfPablo We need to release resources on exceptions.

@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: b80e9416-c61b-4d19-821c-8f7dd901035d

📥 Commits

Reviewing files that changed from the base of the PR and between ae51533 and 5df14a0.

📒 Files selected for processing (1)
  • src/flb_log.c

📝 Walkthrough

Walkthrough

flb_log_create now returns NULL after worker-context creation fails and cleanup completes.

Changes

Log creation error handling

Layer / File(s) Summary
Worker allocation failure path
src/flb_log.c
flb_log_create returns NULL after cleaning up when flb_worker_context_create fails. Subsequent worker initialization is skipped.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Suggested reviewers: edsiper

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the missing NULL return added after worker-context creation fails in flb_log_create.
Linked Issues check ✅ Passed The change directly implements issue #12203 by stopping execution after cleanup when worker creation fails.
Out of Scope Changes check ✅ Passed The single-line change is limited to the linked issue's control-flow fix and introduces no unrelated changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Comment thread src/flb_log.c
mk_event_loop_destroy(log->evl);
flb_free(log);
config->log = NULL;
return NULL;

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.

^ @MsfPablo We need to release resources on exceptions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

flb_log_create: missing return after worker allocation failure

3 participants