2020-06-24 22:36:03

by Antonio Quartulli

[permalink] [raw]
Subject: [PATCH] crda: don't memset ctx before releasing members

reglib_free_regdb_ctx() is currently memsetting the passed context to
all 0s and then attempts to unmap/release its members.

Obviouly this can't work, because after the memset() all ctx's members
will not be useful anymore. Attempting to release them may actually lead
to crashes. Even if no crash should happen, this operation will still
result in memleaks.

Fix this issue by removing the memset() at all, thus leaving the members
intact so that they can be properly released.

Signed-off-by: Kelvin Chui <[email protected]>
Signed-off-by: Antonio Quartulli <[email protected]>
---
reglib.c | 1 -
1 file changed, 1 deletion(-)

diff --git a/reglib.c b/reglib.c
index 4dee401..9a56a6d 100644
--- a/reglib.c
+++ b/reglib.c
@@ -287,7 +287,6 @@ void reglib_free_regdb_ctx(const struct reglib_regdb_ctx *regdb_ctx)

ctx = (struct reglib_regdb_ctx *) regdb_ctx;

- memset(ctx, 0, sizeof(struct reglib_regdb_ctx));
close(ctx->fd);
munmap(ctx->db, ctx->real_dblen);
free(ctx);
--
2.27.0


2020-09-25 08:13:59

by Antonio Quartulli

[permalink] [raw]
Subject: Re: [PATCH] crda: don't memset ctx before releasing members

Hi guys,

On 25/06/2020 00:12, Antonio Quartulli wrote:
> reglib_free_regdb_ctx() is currently memsetting the passed context to
> all 0s and then attempts to unmap/release its members.
>
> Obviouly this can't work, because after the memset() all ctx's members
> will not be useful anymore. Attempting to release them may actually lead
> to crashes. Even if no crash should happen, this operation will still
> result in memleaks.
>
> Fix this issue by removing the memset() at all, thus leaving the members
> intact so that they can be properly released.
>
> Signed-off-by: Kelvin Chui <[email protected]>
> Signed-off-by: Antonio Quartulli <[email protected]>


Just checking if this patch is still of interest and if there is
something I could do to get it merged?

Best Regards,


--
Antonio Quartulli