Skip to content

MEMORY_LEAK in falcosecurity/libs/userspace/libpman/src/ringbuffer.c:170 #2866

@guschin058

Description

@guschin058

Dynamic memory, referenced by 'ringbufs_fds', is allocated at ringbuffer.c:124 by calling function 'calloc' and lost at ringbuffer.c:170.

At the beginning of the pman_finalize_ringbuf_array_after_loading() function, memory is dynamically allocated for the ringbufs_fds array using calloc, after which ring buffer maps are created and the rb_manager manager is initialized. Most branches with errors correctly use the goto clean_percpu_ring_buffers transition, which leads to the execution of a common cleanup block: the created file descriptors are closed and free(ringbufs_fds) is called. However, in the branch where the result of the bpf_map__fd(...) call is checked, when the value is <= 0, a direct return errno (line 167-171); is executed, which bypasses the general cleanup block.

Therefore, you should probably add free(ringbufs_fds) before errno.

https://github.com/falcosecurity/libs/blob/master/userspace/libpman/src/ringbuffer.c#L124

int *ringbufs_fds = (int *)calloc(g_state.n_required_buffers, sizeof(int));

https://github.com/falcosecurity/libs/blob/master/userspace/libpman/src/ringbuffer.c#L167

ringubuf_array_fd = bpf_map__fd(g_state.skel->maps.ringbuf_maps);
if(ringubuf_array_fd <= 0) {
	pman_print_errorf("failed to get the ringubuf_array");
	return errno;
}

Found Linux Verification Center ( linuxtesting.org ) with SVACE
Reporter: Gushchin Egor ( guschin058@yandex.ru )

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions