Skip to content

fix some FDs leaks#334

Merged
AkihiroSuda merged 6 commits intorootless-containers:masterfrom
giuseppe:fix-leaks
Feb 6, 2024
Merged

fix some FDs leaks#334
AkihiroSuda merged 6 commits intorootless-containers:masterfrom
giuseppe:fix-leaks

Conversation

@giuseppe
Copy link
Copy Markdown
Collaborator

@giuseppe giuseppe commented Feb 6, 2024

more information in each commit message.

Found by static analysis.

Signed-off-by: Giuseppe Scrivano <[email protected]>
it is freed with "free" in different places, so allocate using the
stdlib function.

Signed-off-by: Giuseppe Scrivano <[email protected]>
it is allocated using g_malloc0 and passed to a list, that is later
freed with g_free.

Signed-off-by: Giuseppe Scrivano <[email protected]>
Signed-off-by: Giuseppe Scrivano <[email protected]>
Signed-off-by: Giuseppe Scrivano <[email protected]>
Signed-off-by: Giuseppe Scrivano <[email protected]>
@giuseppe
Copy link
Copy Markdown
Collaborator Author

giuseppe commented Feb 6, 2024

@AkihiroSuda PTAL

@AkihiroSuda AkihiroSuda added this to the v1.2.3 milestone Feb 6, 2024
Comment thread api.c
struct api_ctx *api_ctx_alloc(struct slirp4netns_config *cfg)
{
struct api_ctx *ctx = (struct api_ctx *)g_malloc0(sizeof(*ctx));
struct api_ctx *ctx = (struct api_ctx *)calloc(1, sizeof(*ctx));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

g_malloc0 using malloc internally is just an implementation detail. Since we free ctx with free, we should either change g_malloc() -> malloc(), or free() with g_free().

Copy link
Copy Markdown
Member

@AkihiroSuda AkihiroSuda left a comment

Choose a reason for hiding this comment

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

Thanks

@AkihiroSuda AkihiroSuda merged commit 51ef0a9 into rootless-containers:master Feb 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants