[PATCH 11/40] crda: fix intersect.c memory management

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: "Luis R. Rodriguez" <mcgrof@xxxxxxxxxxxxxxxx>

We didn't free memory in some cases, fix this and
to help with the complexity also simplify the case
where any regdom_intersect() fails by completely
failing. In such cases we need an alternative strategy
to build "world regulatory" domains.

Signed-off-by: Luis R. Rodriguez <mcgrof at do-not-panic.com>
---
 intersect.c |   34 +++++++++++++---------------------
 1 file changed, 13 insertions(+), 21 deletions(-)

diff --git a/intersect.c b/intersect.c
index 169fe1a..970f4db 100644
--- a/intersect.c
+++ b/intersect.c
@@ -24,8 +24,10 @@ int main(int argc, char **argv)
 
 	/* We intersect only when we have to rd structures ready */
 	reglib_for_each_country(rd, idx, argv[1]) {
-		if (is_world_regdom((const char *) rd->alpha2))
+		if (is_world_regdom((const char *) rd->alpha2)) {
+			free((struct ieee80211_regdomain *) rd);
 			continue;
+		}
 
 		if (!prev_world) {
 			prev_world = (struct ieee80211_regdomain *) rd;
@@ -39,18 +41,10 @@ int main(int argc, char **argv)
 
 		world = regdom_intersect(prev_world, rd);
 		if (!world) {
-			/* Could be something else but we'll live with this */
-			r = -ENOMEM;
-			if (intersected)
-				fprintf(stderr, "Could not intersect world "
-					"with country (%.2s)\n",
-					rd->alpha2);
-			else
-				fprintf(stderr, "Could not intersect country (%.2s) "
-					"with country (%.2s)\n",
-					prev_world->alpha2,
-					rd->alpha2);
-			continue;
+			free(prev_world);
+			free((struct ieee80211_regdomain *) rd);
+			fprintf(stderr, "Intersection not possible\n");
+			return -ENOENT;
 		}
 
 		if (intersected)
@@ -71,6 +65,7 @@ int main(int argc, char **argv)
 				rd->n_reg_rules,
 				world->n_reg_rules);
 		intersected++;
+		free((struct ieee80211_regdomain *) rd);
 	}
 
 	if (!idx) {
@@ -83,28 +78,25 @@ int main(int argc, char **argv)
 		printf("%d regulatory domains intersected\n", intersected);
 	else {
 		world = prev_world;
+		prev_world = NULL;
 		printf("No intersections completed\n");
 		if (idx > 1) {
 			printf("Since more than one regulatory domain is "
 			       "present and no intersections were possible "
 			       "no globally allowed spectrum is possible so "
 			       "consider enabling passive scan flags\n");
+			free(world);
 			return r;
 		}
 	}
 
+	if (prev_world)
+		free(prev_world);
+
 	/* Tada! */
 	printf("== World regulatory domain: ==\n");
 	print_regdom(world);
 
-	if (!intersected) {
-		free(world);
-		return r;
-	}
-	if (intersected > 1) {
-		free((struct ieee80211_regdomain *)rd);
-		free(prev_world);
-	}
 	free(world);
 	return r;
 }
-- 
1.7.10.4




[Index of Archives]     [LM Sensors]     [Linux Sound]     [ALSA Users]     [ALSA Devel]     [Linux Audio Users]     [Linux Media]     [Kernel]     [Gimp]     [Yosemite News]     [Linux Media]

  Powered by Linux