- remove dead assignments
[oweals/gnunet.git] / src / testbed / testbed_api_operations.c
index ed8461606ac5ec89a4d99486887576f1a5be45b2..a418de91073f69266cab8643b8a7bcbd2b0dda86 100644 (file)
@@ -470,7 +470,6 @@ decide_capacity (struct OperationQueue *opq,
   rval = GNUNET_YES;
   if (opq->active > opq->max_active)
   {
-    need += opq->active - opq->max_active;
     rval = GNUNET_NO;
     goto ret;
   }
@@ -497,8 +496,12 @@ decide_capacity (struct OperationQueue *opq,
 
  ret:
   GNUNET_free_non_null (evict_entries);  
-  if (NULL != ops_) *ops_ = ops;
-  if (NULL != n_ops_) *n_ops_ = n_ops;
+  if (NULL != ops_)
+    *ops_ = ops;
+  else
+    GNUNET_free (ops);
+  if (NULL != n_ops_)
+    *n_ops_ = n_ops;
   return rval;
 }
 
@@ -548,7 +551,7 @@ merge_ops (struct GNUNET_TESTBED_Operation ***old,
  *
  * @param op the operation
  */
-static void
+static int
 check_readiness (struct GNUNET_TESTBED_Operation *op)
 {
   struct GNUNET_TESTBED_Operation **evict_ops;
@@ -569,7 +572,7 @@ check_readiness (struct GNUNET_TESTBED_Operation *op)
                                       &ops, &n_ops))
     {
       GNUNET_free_non_null (evict_ops);
-      return;
+      return GNUNET_NO;
     }
     if (NULL == ops)
       continue;
@@ -584,12 +587,13 @@ check_readiness (struct GNUNET_TESTBED_Operation *op)
     evict_ops = NULL;
     /* Evicting the operations should schedule this operation */
     GNUNET_assert (OP_STATE_READY == op->state);
-    return;
+    return GNUNET_YES;
   }
   for (i = 0; i < op->nqueues; i++)
     op->queues[i]->active += op->nres[i];
   change_state (op, OP_STATE_READY);
   rq_add (op);
+  return GNUNET_YES;
 }
 
 
@@ -699,7 +703,8 @@ recheck_waiting (struct OperationQueue *opq)
   while (NULL != entry)
   {
     entry2 = entry->next;
-    check_readiness (entry->op);
+    if (GNUNET_NO == check_readiness (entry->op))
+      break;
     entry = entry2;
   }
 }
@@ -786,7 +791,7 @@ GNUNET_TESTBED_operation_begin_wait_ (struct GNUNET_TESTBED_Operation *op)
 {
   GNUNET_assert (NULL == op->rq_entry);
   change_state (op, OP_STATE_WAITING);
-  check_readiness (op);
+  (void) check_readiness (op);
 }
 
 
@@ -812,6 +817,8 @@ GNUNET_TESTBED_operation_inactivate_ (struct GNUNET_TESTBED_Operation *op)
   nqueues = op->nqueues;
   ms = sizeof (struct OperationQueue *) * nqueues;
   queues = GNUNET_malloc (ms);
+  /* Cloning is needed as the operation be released by waiting operations and
+     hence its nqueues memory ptr will be freed */
   GNUNET_assert (NULL != (queues = memcpy (queues, op->queues, ms)));
   for (i = 0; i < nqueues; i++)
     recheck_waiting (queues[i]);