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_docker: fix error handling if some resources not found #5189

Merged
merged 1 commit into from
Apr 26, 2022
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
34 changes: 33 additions & 1 deletion plugins/in_docker/docker.c
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,7 @@ static bool is_exists(struct mk_list *list, char *id)
return result;
}

static void free_snapshots(struct mk_list *snaps);
/* Returns dockers CPU/Memory metrics. */
static struct mk_list *get_docker_stats(struct flb_docker *ctx, struct mk_list *dockers)
{
Expand All @@ -499,9 +500,35 @@ static struct mk_list *get_docker_stats(struct flb_docker *ctx, struct mk_list *
mk_list_foreach(head, dockers) {
docker = mk_list_entry(head, docker_info, _head);
snapshot = init_snapshot(docker->id);
if (snapshot == NULL) {
free_snapshots(snapshots);
return NULL;
}
snapshot->name = get_container_name(ctx, docker->id);
if (snapshot->name == NULL) {
free_snapshots(snapshots);
flb_free(snapshot->id);
flb_free(snapshot);
return NULL;
}
snapshot->cpu = get_docker_cpu_snapshot(ctx, docker->id);
if (snapshot->cpu == NULL) {
free_snapshots(snapshots);
flb_free(snapshot->name);
flb_free(snapshot->id);
flb_free(snapshot);
return NULL;
}
snapshot->mem = get_docker_mem_snapshot(ctx, docker->id);
if (snapshot->mem == NULL) {
free_snapshots(snapshots);
flb_free(snapshot->cpu);
flb_free(snapshot->name);
flb_free(snapshot->id);
flb_free(snapshot);
return NULL;
}

mk_list_add(&snapshot->_head, snapshots);
}

Expand Down Expand Up @@ -791,7 +818,12 @@ static int cb_docker_collect(struct flb_input_instance *ins,
snaps = get_docker_stats(ctx, filtered);
if (!snaps) {
free_docker_list(active);
free_docker_list(filtered);
if (active != filtered) {
/* apply_filters can return the address of acive.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

* In that case, filtered is already freed.
*/
free_docker_list(filtered);
}
return 0;
}

Expand Down