]> git.ipfire.org Git - thirdparty/collectd.git/commit
src: fix memory leak in config parser in write_syslog.c 4361/head
authorAntonMoryakov <ant.v.moryakov@gmail.com>
Wed, 14 May 2025 16:11:04 +0000 (19:11 +0300)
committerAntonMoryakov <ant.v.moryakov@gmail.com>
Wed, 14 May 2025 16:11:12 +0000 (19:11 +0300)
commit5d3073c3e96996af133b53867b43934bd60c350e
tree326921220b9b66d67c7271d7a774054c2035ecb9
parent14c59711e8470798428845ea2ecbdbe28fceb164
src: fix memory leak in config parser in write_syslog.c

Static analyzer detected (write_syslog.c:562):
- Memory allocated for `cb` via `calloc()` was lost when returning -1
  due to invalid config options (before line 594)

Root cause:
- The function `ws_config_tsd()` could return early on config errors
  without freeing `cb`, while successful path used `user_data.free_func`
  for cleanup.

Fix:
- Added explicit cleanup with `ws_callback_free(cb)` before all error returns
- Only one error return path needed fixing (invalid option case)
- Success path still uses automatic cleanup via `user_data.free_func`

Impact:
- Fixes memory leak that could occur on every invalid configuration
- No behavioral changes for valid configurations
- Maintains existing cleanup strategy

Triggers found by static analyzer Svace.

Signed-off-by: Anton Moryakov <ant.v.moryakov@gmail.com>
src/write_syslog.c