Skip to contentSkip to conversation

crda: don't memset ctx before releasing members

PATCH In review Antonio Quartulli 1 participant 2 messages Jun 24, 2020 – Sep 25, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

---
 reglib.c | 1 -
 1 file changed, 1 deletion(-)
reglib.c +0 -1
index 4dee401..9a56a6d 100644
@@ -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);
Signature · 1 line
2.27.0
#1 lore raw

Hi guys,

Quoted 8 lines · Antonio Quartulli

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.

Quoted 5 lines

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

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

Best Regards,

Signature · 1 line
Antonio Quartulli