Skip to content

Commit

Permalink
sp: fix memory leak when snapshot creation fails
Browse files Browse the repository at this point in the history
Signed-off-by: Masoud Koleini <[email protected]>
  • Loading branch information
koleini authored and edsiper committed Feb 23, 2020
1 parent e0fc535 commit 05bb774
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/stream_processor/flb_sp.c
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,7 @@ int flb_sp_snapshot_create(struct flb_sp_task *task)
if (snapshot->time_limit == 0 && snapshot->record_limit == 0) {
flb_error("[sp] could not create snapshot '%s': size is not defined",
cmd->stream_name);
flb_sp_snapshot_destroy(snapshot);
return -1;
}

Expand Down
11 changes: 7 additions & 4 deletions src/stream_processor/flb_sp_snapshot.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ static int snapshot_cleanup(struct flb_sp_snapshot *snapshot, struct flb_time *t
struct flb_sp_snapshot_page *page;

ok = MSGPACK_UNPACK_SUCCESS;
off = 0;

while (mk_list_is_empty(&snapshot->pages) != 0) {
page = mk_list_entry_first(&snapshot->pages, struct flb_sp_snapshot_page,
Expand Down Expand Up @@ -115,7 +116,7 @@ static bool snapshot_page_is_full(struct flb_sp_snapshot_page *page, size_t buf_

char *flb_sp_snapshot_name_from_flush(flb_sds_t name)
{
return name + strlen("__flush_");
return name + sizeof("__flush_") - 1;
}

int flb_sp_snapshot_update(struct flb_sp_task *task, const char *buf_data,
Expand Down Expand Up @@ -188,6 +189,7 @@ int flb_sp_snapshot_flush(struct flb_sp *sp, struct flb_sp_task *task,
size_t off;
size_t page_size;
char *snapshot_name;
char *out_buf_data_tmp;
struct flb_sp_cmd *cmd;
struct mk_list *tmp;
struct mk_list *head;
Expand Down Expand Up @@ -224,12 +226,13 @@ int flb_sp_snapshot_flush(struct flb_sp *sp, struct flb_sp_task *task,
*out_buf_size = snapshot->size;
}
else {
*out_buf_data = (char *) flb_realloc(*out_buf_data,
*out_buf_size + snapshot->size);
if (!*out_buf_data) {
out_buf_data_tmp = (char *) flb_realloc(*out_buf_data,
*out_buf_size + snapshot->size);
if (!out_buf_data_tmp) {
flb_errno();
return -1;
}
*out_buf_data = out_buf_data_tmp;
*out_buf_size = *out_buf_size + snapshot->size;
}

Expand Down
3 changes: 0 additions & 3 deletions src/stream_processor/parser/flb_sp_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -458,9 +458,6 @@ int flb_sp_cmd_snapshot_flush_new(struct flb_sp_cmd *cmd, const char *snapshot_n

cmd->type = FLB_SP_FLUSH_SNAPSHOT;

/* Use filesystem storage by default for flushing */
flb_sp_cmd_stream_prop_add(cmd, "storage.type", "filesystem");

return 0;
}

Expand Down

0 comments on commit 05bb774

Please sign in to comment.