diff mbox series

crda: don't memset ctx before releasing members

Message ID 20200624221221.16419-1-a@unstable.cc (mailing list archive)
State Not Applicable
Delegated to: Johannes Berg
Headers show
Series crda: don't memset ctx before releasing members | expand

Commit Message

Antonio Quartulli June 24, 2020, 10:12 p.m. UTC
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 <kelvin.chui@kaiwoo.ai>
Signed-off-by: Antonio Quartulli <a@unstable.cc>
---
 reglib.c | 1 -
 1 file changed, 1 deletion(-)

Comments

Antonio Quartulli Sept. 25, 2020, 7:54 a.m. UTC | #1
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 <kelvin.chui@kaiwoo.ai>
> Signed-off-by: Antonio Quartulli <a@unstable.cc>


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

Best Regards,
diff mbox series

Patch

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);