Revision
16842
Author
mochouinard
Date
2010-02-27 10:24:09 -0600 (Sat, 27 Feb 2010)

Log Message

mod_distributor: Fix segfault when no node are added, and add the support to have a single node with total weight of 1 only

Modified Paths

Diff

Modified: freeswitch/trunk/src/mod/applications/mod_distributor/mod_distributor.c (16841 => 16842)


--- freeswitch/trunk/src/mod/applications/mod_distributor/mod_distributor.c	2010-02-26 20:57:37 UTC (rev 16841)
+++ freeswitch/trunk/src/mod/applications/mod_distributor/mod_distributor.c	2010-02-27 16:24:09 UTC (rev 16842)
@@ -157,7 +157,7 @@
 				continue;
 			}
 
-			if (tmp >= lp->target_weight) {
+			if (tmp >= lp->target_weight && (lp->target_weight == 1 && tmp != 1)) {
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Weight %d value incorrect, must be less than %d\n", tmp, lp->target_weight);
 				continue;
 			}
@@ -196,7 +196,7 @@
 		if (accum < lp->target_weight) {
 			struct dist_node *np1;
 			int remain = lp->target_weight - accum;
-			int ea = remain / lp->node_count ? lp->node_count : 1;
+			int ea = remain / (lp->node_count ? lp->node_count : 1);
 
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Total weight does not add up to total weight %d\n", lp->target_weight);