Skip to content

kafka: use rd_kafka_conf_destroy in flb_kafka_conf_create error path#11859

Open
immanuwell wants to merge 1 commit into
fluent:masterfrom
immanuwell:fix/kafka-conf-destroy
Open

kafka: use rd_kafka_conf_destroy in flb_kafka_conf_create error path#11859
immanuwell wants to merge 1 commit into
fluent:masterfrom
immanuwell:fix/kafka-conf-destroy

Conversation

@immanuwell

@immanuwell immanuwell commented May 28, 2026

Copy link
Copy Markdown

flb_kafka_conf_create leaks memory when it hits the error path (e.g. missing brokers config). code calls flb_free(kafka_cfg) on the rd_kafka_conf_t* from rd_kafka_conf_new(), which skips rd_kafka_anyconf_destroy() and leaves all internal strings (default props, client.id, group.id) hanging in memory.

one-line fix: swap flb_free for rd_kafka_conf_destroy. every other caller in the codebase already does this (in_kafka.c:459, out_kafka/kafka_config.c:255,320).

How to repro: configure a kafka output without brokers and run under valgrind:

[OUTPUT]
    name  kafka
    topic test

valgrind will show leaks from rd_kafka_conf_set allocations that never get freed on teardown.


Enter [N/A] in the box, if an item is not applicable to your change.

Testing
Before we can approve your change; please submit the following in a comment:

  • Example configuration file for the change (above)
  • [N/A] Debug log output from testing the change
  • Attached Valgrind output that shows no leaks or memory corruption was found

Documentation

  • [N/A] Documentation required for this feature

Backporting

  • Backport to latest stable release.

Fluent Bit is licensed under Apache 2.0, by submitting this pull request I understand that this code will be released under the terms of that license.

Summary by CodeRabbit

  • Bug Fixes
    • Corrected error handling in Kafka initialization to ensure proper cleanup of configuration resources when startup fails.

Review Change Stack

The error path in flb_kafka_conf_create called flb_free() on a
rd_kafka_conf_t pointer returned by rd_kafka_conf_new(). This only
frees the top-level struct and skips rd_kafka_anyconf_destroy(),
leaking all internally allocated strings (default config values,
client.id, group.id, etc.).

Replace with rd_kafka_conf_destroy(), which is what every other
caller in the codebase already uses to clean up kafka conf objects.

Signed-off-by: Immanuel Tikhonov <pchpr.00@list.ru>
Signed-off-by: immanuwell <pchpr.00@list.ru>
@coderabbitai

coderabbitai Bot commented May 28, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ba955e44-192f-4298-95d9-8f79e69a218c

📥 Commits

Reviewing files that changed from the base of the PR and between 19cc8f9 and 7a87555.

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

📝 Walkthrough

Walkthrough

A single-line fix in the error cleanup path of flb_kafka_conf_create() that correctly uses rd_kafka_conf_destroy() to release the rdkafka configuration object instead of flb_free(), aligning destruction with the rdkafka allocation lifecycle.

Changes

rdkafka Config Cleanup

Layer / File(s) Summary
Error cleanup in conf_create
src/flb_kafka.c
flb_kafka_conf_create() error handling now destroys rd_kafka_conf_t using rd_kafka_conf_destroy() instead of flb_free().

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Possibly related PRs

  • fluent/fluent-bit#11359: Both PRs fix incorrect rdkafka rd_kafka_conf_t cleanup on rd_kafka_new()/initialization failure by switching to rd_kafka_conf_destroy(...) instead of freeing the config object directly.

Suggested labels

backport to v4.2.x

Suggested reviewers

  • edsiper
  • cosmo0920
  • patrick-stephens
  • fujimotos

Poem

🐰 A config so fine, now freed the right way,
With rdkafka's own destroy to save the day,
No more confusion when init goes south,
Cleanup flows true from source to mouth! 🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: replacing flb_free with rd_kafka_conf_destroy in the error path of flb_kafka_conf_create, which is exactly what the changeset does.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 and usage tips.

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.

1 participant