Skip to contentSkip to conversation

src: callback: fix memory leak when ct has dynamically allocated attr

PATCH In review Florian Westphal 2 participants 2 messages Jul 3, 2013 netfilter

lore
Share & tools
lore

Florian Westphal

author maintainer
#0 lore raw

PATCH 1/1 src: callback: fix memory leak when ct has dynamically allocated attr

Must free ct and exp using the _destroy functions, else we leak attributes with malloc'd data.

---
 src/callback.c |   34 ++++++++--------------------------
 1 files changed, 8 insertions(+), 26 deletions(-)
src/callback.c +8 -26
index 684d3b2..19cc663 100644
@@ -82,31 +82,13 @@ int __callback(struct nlmsghdr *nlh, struct nfattr *nfa[], void *data)
 		break;
 	}
 
-	switch(ret) {
-	case NFCT_CB_FAILURE:
-		if (ct)
-			free(ct);
-		if (exp)
-			free(exp);
-		ret = NFNL_CB_FAILURE;
-		break;
-	case NFCT_CB_STOP:
-		if (ct)
-			free(ct);
-		if (exp)
-			free(exp);
-		ret = NFNL_CB_STOP;
-		break;
-	case NFCT_CB_CONTINUE:
-		if (ct)
-			free(ct);
-		if (exp)
-			free(exp);
-		ret = NFNL_CB_CONTINUE;
-		break;
-	case NFCT_CB_STOLEN:
-		ret = NFNL_CB_CONTINUE;
-		break;
-	}
+	if (ret == NFCT_CB_STOLEN)
+		return NFNL_CB_CONTINUE;
+
+	if (ct)
+		nfct_destroy(ct);
+	if (exp)
+		nfexp_destroy(exp);
+
 	return ret;
 }
Signature · 1 line
1.7.8.6
#1 lore raw
Quoted 1 line · Florian Westphal

Must free ct and exp using the _destroy functions, else we leak attributes with malloc'd data.

Looks good, push it please.