Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

in_systemd: fix memory leak #9773

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 9 additions & 24 deletions plugins/in_systemd/systemd.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ static int systemd_enumerate_data_store(struct flb_config *config,
const char *sep;
const char *key;
const char *val;
char *buf = NULL;
char *buf;
struct cfl_kvlist *kvlist = format_context;
struct flb_systemd_config *ctx = plugin_context;
struct cfl_variant *cfl_val = NULL;
Expand All @@ -155,31 +155,19 @@ static int systemd_enumerate_data_store(struct flb_config *config,

len = (sep - key);
key_len = len;

if (ctx->lowercase == FLB_TRUE) {
/*
* Ensure buf to have enough space for the key because the libsystemd
* might return larger data than the threshold.
*/
if (buf == NULL) {
buf = flb_sds_create_len(NULL, ctx->threshold);
}
if (flb_sds_alloc(buf) < len) {
buf = flb_sds_increase(buf, len - flb_sds_alloc(buf));
}
for (i = 0; i < len; i++) {
buf[i] = tolower(key[i]);
}
list_key = flb_sds_create_len(buf, key_len);
}
else {
list_key = flb_sds_create_len(key, key_len);
}
list_key = flb_sds_create_len(key, key_len);

if (!list_key) {
return -1;
}

if (ctx->lowercase == FLB_TRUE) {
buf = list_key;
for (i = 0; i < key_len; i++) {
buf[i] = tolower(buf[i]);
}
}

/* Check existence */
cfl_val = NULL;
cfl_val = cfl_kvlist_fetch_s(kvlist, list_key, key_len);
Expand Down Expand Up @@ -274,7 +262,6 @@ static int in_systemd_collect(struct flb_input_instance *ins,
uint64_t usec;
size_t length;
const char *key;
char *buf = NULL;
#ifdef FLB_HAVE_SQLDB
char *cursor = NULL;
#endif
Expand Down Expand Up @@ -458,8 +445,6 @@ static int in_systemd_collect(struct flb_input_instance *ins,
}
}

flb_sds_destroy(buf);

#ifdef FLB_HAVE_SQLDB
/* Save cursor */
if (ctx->db) {
Expand Down
Loading