aboutsummaryrefslogtreecommitdiff
path: root/src/testbed
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2012-07-24 13:46:12 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2012-07-24 13:46:12 +0000
commit8b9b2ab39943070706515485cff6e23cbb564003 (patch)
treea7944312a411fee199bbdaa9ef3e47688ad08da4 /src/testbed
parentdd177ca10b140d68c79335c900b34a77f33cc98b (diff)
downloadgnunet-8b9b2ab39943070706515485cff6e23cbb564003.tar.gz
gnunet-8b9b2ab39943070706515485cff6e23cbb564003.zip
fixed mem leaks with operations
Diffstat (limited to 'src/testbed')
-rw-r--r--src/testbed/test_testbed_api.c5
-rw-r--r--src/testbed/testbed_api.c103
-rw-r--r--src/testbed/testbed_api.h5
-rw-r--r--src/testbed/testbed_api_operations.c41
-rw-r--r--src/testbed/testbed_api_operations.h10
-rw-r--r--src/testbed/testbed_api_peers.c5
-rw-r--r--src/testbed/testbed_api_peers.h28
7 files changed, 143 insertions, 54 deletions
diff --git a/src/testbed/test_testbed_api.c b/src/testbed/test_testbed_api.c
index ba026cb65..0d2a9d677 100644
--- a/src/testbed/test_testbed_api.c
+++ b/src/testbed/test_testbed_api.c
@@ -180,6 +180,7 @@ controller_cb(void *cls, const struct GNUNET_TESTBED_EventInformation *event)
180 event->details.operation_finished.pit); 180 event->details.operation_finished.pit);
181 GNUNET_assert (NULL != event->details.operation_finished.op_result.cfg); 181 GNUNET_assert (NULL != event->details.operation_finished.op_result.cfg);
182 sub_test = PEER_DESTROY; 182 sub_test = PEER_DESTROY;
183 GNUNET_TESTBED_operation_done (operation);
183 operation = GNUNET_TESTBED_peer_destroy (peer); 184 operation = GNUNET_TESTBED_peer_destroy (peer);
184 break; 185 break;
185 case PEER_DESTROY: 186 case PEER_DESTROY:
@@ -190,6 +191,7 @@ controller_cb(void *cls, const struct GNUNET_TESTBED_EventInformation *event)
190 event->details.operation_finished.pit); 191 event->details.operation_finished.pit);
191 GNUNET_assert (NULL == 192 GNUNET_assert (NULL ==
192 event->details.operation_finished.op_result.generic); 193 event->details.operation_finished.op_result.generic);
194 GNUNET_TESTBED_operation_done (operation);
193 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); 195 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
194 break; 196 break;
195 case OTHER: 197 case OTHER:
@@ -200,12 +202,14 @@ controller_cb(void *cls, const struct GNUNET_TESTBED_EventInformation *event)
200 case GNUNET_TESTBED_ET_PEER_START: 202 case GNUNET_TESTBED_ET_PEER_START:
201 GNUNET_assert (event->details.peer_start.host == host); 203 GNUNET_assert (event->details.peer_start.host == host);
202 GNUNET_assert (event->details.peer_start.peer == peer); 204 GNUNET_assert (event->details.peer_start.peer == peer);
205 GNUNET_TESTBED_operation_done (operation);
203 operation = GNUNET_TESTBED_peer_stop (peer); 206 operation = GNUNET_TESTBED_peer_stop (peer);
204 break; 207 break;
205 case GNUNET_TESTBED_ET_PEER_STOP: 208 case GNUNET_TESTBED_ET_PEER_STOP:
206 GNUNET_assert (event->details.peer_stop.peer == peer); 209 GNUNET_assert (event->details.peer_stop.peer == peer);
207 result = GNUNET_YES; 210 result = GNUNET_YES;
208 sub_test = PEER_GETCONFIG; 211 sub_test = PEER_GETCONFIG;
212 GNUNET_TESTBED_operation_done (operation);
209 operation = 213 operation =
210 GNUNET_TESTBED_peer_get_information (peer, 214 GNUNET_TESTBED_peer_get_information (peer,
211 GNUNET_TESTBED_PIT_CONFIGURATION); 215 GNUNET_TESTBED_PIT_CONFIGURATION);
@@ -235,6 +239,7 @@ peer_create_cb (void *cls,
235 GNUNET_assert (NULL != peer); 239 GNUNET_assert (NULL != peer);
236 GNUNET_assert (NULL != peer_ptr); 240 GNUNET_assert (NULL != peer_ptr);
237 *peer_ptr = peer; 241 *peer_ptr = peer;
242 GNUNET_TESTBED_operation_done (operation);
238 operation = GNUNET_TESTBED_peer_start (peer); 243 operation = GNUNET_TESTBED_peer_start (peer);
239 GNUNET_assert (NULL != operation); 244 GNUNET_assert (NULL != operation);
240} 245}
diff --git a/src/testbed/testbed_api.c b/src/testbed/testbed_api.c
index 6fce5adde..708fc1d04 100644
--- a/src/testbed/testbed_api.c
+++ b/src/testbed/testbed_api.c
@@ -267,14 +267,14 @@ handle_opsuccess (struct GNUNET_TESTBED_Controller *c,
267 } 267 }
268 GNUNET_free (data->peer); 268 GNUNET_free (data->peer);
269 GNUNET_free (data); 269 GNUNET_free (data);
270 op->data = NULL;
270 //PEERDESTROYDATA 271 //PEERDESTROYDATA
271 } 272 }
272 break; 273 break;
273 default: 274 default:
274 GNUNET_break (0); 275 GNUNET_assert (0);
275 } 276 }
276 GNUNET_CONTAINER_DLL_remove (c->op_head, c->op_tail, op); 277 GNUNET_CONTAINER_DLL_remove (c->op_head, c->op_tail, op);
277 GNUNET_free (op);
278 if (NULL != event) 278 if (NULL != event)
279 { 279 {
280 if (NULL != c->cc) 280 if (NULL != c->cc)
@@ -327,9 +327,9 @@ handle_peer_create_success (struct GNUNET_TESTBED_Controller *c,
327 GNUNET_assert (peer->unique_id == ntohl (msg->peer_id)); 327 GNUNET_assert (peer->unique_id == ntohl (msg->peer_id));
328 cb = data->cb; 328 cb = data->cb;
329 cls = data->cls; 329 cls = data->cls;
330 GNUNET_CONTAINER_DLL_remove (c->op_head, c->op_tail, op);
331 GNUNET_free (data); 330 GNUNET_free (data);
332 GNUNET_free (op); 331 op->data = NULL;
332 GNUNET_CONTAINER_DLL_remove (c->op_head, c->op_tail, op);
333 if (NULL != cb) 333 if (NULL != cb)
334 cb (cls, peer, NULL); 334 cb (cls, peer, NULL);
335 return GNUNET_YES; 335 return GNUNET_YES;
@@ -382,9 +382,8 @@ handle_peer_event (struct GNUNET_TESTBED_Controller *c,
382 break; 382 break;
383 default: 383 default:
384 GNUNET_assert (0); /* We should never reach this state */ 384 GNUNET_assert (0); /* We should never reach this state */
385 } 385 }
386 GNUNET_CONTAINER_DLL_remove (c->op_head, c->op_tail, op); 386 GNUNET_CONTAINER_DLL_remove (c->op_head, c->op_tail, op);
387 GNUNET_free (op);
388 if (0 != ((GNUNET_TESTBED_ET_PEER_START | GNUNET_TESTBED_ET_PEER_STOP) 387 if (0 != ((GNUNET_TESTBED_ET_PEER_START | GNUNET_TESTBED_ET_PEER_STOP)
389 & c->event_mask)) 388 & c->event_mask))
390 { 389 {
@@ -411,6 +410,7 @@ handle_peer_config (struct GNUNET_TESTBED_Controller *c,
411 struct GNUNET_TESTBED_Operation *op; 410 struct GNUNET_TESTBED_Operation *op;
412 struct GNUNET_TESTBED_Peer *peer; 411 struct GNUNET_TESTBED_Peer *peer;
413 struct PeerInfoData *data; 412 struct PeerInfoData *data;
413 struct PeerInfoData2 *response_data;
414 struct GNUNET_TESTBED_EventInformation info; 414 struct GNUNET_TESTBED_EventInformation info;
415 uint64_t op_id; 415 uint64_t op_id;
416 416
@@ -432,24 +432,28 @@ handle_peer_config (struct GNUNET_TESTBED_Controller *c,
432 GNUNET_assert (ntohl (msg->peer_id) == peer->unique_id); 432 GNUNET_assert (ntohl (msg->peer_id) == peer->unique_id);
433 if (0 == (c->event_mask & (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED))) 433 if (0 == (c->event_mask & (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED)))
434 { 434 {
435 LOG_DEBUG ("Skipping operation callback as flag not set\n");
435 GNUNET_CONTAINER_DLL_remove (c->op_head, c->op_tail, op); 436 GNUNET_CONTAINER_DLL_remove (c->op_head, c->op_tail, op);
436 GNUNET_free (data);
437 GNUNET_free (op);
438 return GNUNET_YES; 437 return GNUNET_YES;
439 } 438 }
439 response_data = GNUNET_malloc (sizeof (struct PeerInfoData2));
440 response_data->pit = data->pit;
441 GNUNET_free (data);
440 info.type = GNUNET_TESTBED_ET_OPERATION_FINISHED; 442 info.type = GNUNET_TESTBED_ET_OPERATION_FINISHED;
441 info.details.operation_finished.operation = op; 443 info.details.operation_finished.operation = op;
442 info.details.operation_finished.op_cls = NULL; 444 info.details.operation_finished.op_cls = NULL;
443 info.details.operation_finished.emsg = NULL; 445 info.details.operation_finished.emsg = NULL;
444 info.details.operation_finished.pit = data->pit; 446 info.details.operation_finished.pit = response_data->pit;
445 switch (data->pit) 447 switch (response_data->pit)
446 { 448 {
447 case GNUNET_TESTBED_PIT_IDENTITY: 449 case GNUNET_TESTBED_PIT_IDENTITY:
448 { 450 {
449 struct GNUNET_PeerIdentity *peer_identity; 451 struct GNUNET_PeerIdentity *peer_identity;
450 452
451 peer_identity = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); 453 peer_identity = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity));
452 (void) memcpy (peer_identity, &msg->peer_identity, sizeof (struct GNUNET_PeerIdentity)); 454 (void) memcpy (peer_identity, &msg->peer_identity,
455 sizeof (struct GNUNET_PeerIdentity));
456 response_data->details.peer_identity = peer_identity;
453 info.details.operation_finished.op_result.pid = peer_identity; 457 info.details.operation_finished.op_result.pid = peer_identity;
454 } 458 }
455 break; 459 break;
@@ -474,6 +478,7 @@ handle_peer_config (struct GNUNET_TESTBED_Controller *c,
474 (size_t) config_size, 478 (size_t) config_size,
475 GNUNET_NO)); 479 GNUNET_NO));
476 GNUNET_free (config); 480 GNUNET_free (config);
481 response_data->details.cfg = cfg;
477 info.details.operation_finished.op_result.cfg = cfg; 482 info.details.operation_finished.op_result.cfg = cfg;
478 } 483 }
479 break; 484 break;
@@ -481,10 +486,9 @@ handle_peer_config (struct GNUNET_TESTBED_Controller *c,
481 GNUNET_assert (0); /* never reach here */ 486 GNUNET_assert (0); /* never reach here */
482 break; 487 break;
483 } 488 }
484 c->cc (c->cc_cls, &info); 489 op->data = response_data;
485 GNUNET_CONTAINER_DLL_remove (c->op_head, c->op_tail, op); 490 GNUNET_CONTAINER_DLL_remove (c->op_head, c->op_tail, op);
486 GNUNET_free (data); 491 c->cc (c->cc_cls, &info);
487 GNUNET_free (op);
488 return GNUNET_YES; 492 return GNUNET_YES;
489} 493}
490 494
@@ -545,7 +549,9 @@ message_handler (void *cls, const struct GNUNET_MessageHeader *msg)
545 sizeof (struct GNUNET_TESTBED_PeerConfigurationInformationMessage)); 549 sizeof (struct GNUNET_TESTBED_PeerConfigurationInformationMessage));
546 status = 550 status =
547 handle_peer_config 551 handle_peer_config
548 (c, (const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *) msg); 552 (c, (const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *)
553 msg);
554 break;
549 default: 555 default:
550 GNUNET_break (0); 556 GNUNET_break (0);
551 } 557 }
@@ -1295,4 +1301,71 @@ GNUNET_TESTBED_create_helper_init_msg_ (const char *cname,
1295} 1301}
1296 1302
1297 1303
1304/**
1305 * Cancel a pending operation. Releases all resources
1306 * of the operation and will ensure that no event
1307 * is generated for the operation. Does NOT guarantee
1308 * that the operation will be fully undone (or that
1309 * nothing ever happened).
1310 *
1311 * @param operation operation to cancel
1312 */
1313void
1314GNUNET_TESTBED_operation_cancel (struct GNUNET_TESTBED_Operation *operation)
1315{
1316 GNUNET_CONTAINER_DLL_remove (operation->controller->op_head,
1317 operation->controller->op_tail,
1318 operation);
1319 GNUNET_TESTBED_operation_done (operation);
1320}
1321
1322
1323/**
1324 * Signal that the information from an operation has been fully
1325 * processed. This function MUST be called for each event
1326 * of type 'operation_finished' to fully remove the operation
1327 * from the operation queue. After calling this function, the
1328 * 'op_result' becomes invalid (!).
1329 *
1330 * @param operation operation to signal completion for
1331 */
1332void
1333GNUNET_TESTBED_operation_done (struct GNUNET_TESTBED_Operation *operation)
1334{
1335 switch (operation->type)
1336 {
1337 case OP_PEER_CREATE:
1338 GNUNET_free_non_null (operation->data);
1339 break;
1340 case OP_PEER_DESTROY:
1341 GNUNET_free_non_null (operation->data);
1342 break;
1343 case OP_PEER_START:
1344 case OP_PEER_STOP:
1345 break;
1346 case OP_PEER_INFO:
1347 {
1348 struct PeerInfoData2 *data;
1349
1350 data = operation->data;
1351 switch (data->pit)
1352 {
1353 case GNUNET_TESTBED_PIT_IDENTITY:
1354 GNUNET_free (data->details.peer_identity);
1355 break;
1356 case GNUNET_TESTBED_PIT_CONFIGURATION:
1357 GNUNET_CONFIGURATION_destroy (data->details.cfg);
1358 break;
1359 case GNUNET_TESTBED_PIT_GENERIC:
1360 GNUNET_assert (0); /* never reach here */
1361 break;
1362 }
1363 }
1364 GNUNET_free_non_null (operation->data);
1365 break;
1366 }
1367 GNUNET_free (operation);
1368}
1369
1370
1298/* end of testbed_api.c */ 1371/* end of testbed_api.c */
diff --git a/src/testbed/testbed_api.h b/src/testbed/testbed_api.h
index fcfb5008c..1d984ca93 100644
--- a/src/testbed/testbed_api.h
+++ b/src/testbed/testbed_api.h
@@ -76,6 +76,11 @@ struct GNUNET_TESTBED_Operation
76 struct GNUNET_TESTBED_Operation *prev; 76 struct GNUNET_TESTBED_Operation *prev;
77 77
78 /** 78 /**
79 * The controller on which this operation operates
80 */
81 struct GNUNET_TESTBED_Controller *controller;
82
83 /**
79 * The ID for the operation; 84 * The ID for the operation;
80 */ 85 */
81 uint64_t operation_id; 86 uint64_t operation_id;
diff --git a/src/testbed/testbed_api_operations.c b/src/testbed/testbed_api_operations.c
index c98998bbf..31a46d85a 100644
--- a/src/testbed/testbed_api_operations.c
+++ b/src/testbed/testbed_api_operations.c
@@ -146,49 +146,12 @@ GNUNET_TESTBED_operation_queue_remove_ (struct OperationQueue *queue,
146 * 146 *
147 * @param operation operation that finished 147 * @param operation operation that finished
148 */ 148 */
149static void
150operation_release (struct GNUNET_TESTBED_Operation *operation)
151{
152 // call operation->release, remove from queues
153 GNUNET_break (0);
154}
155
156
157/**
158 * Cancel a pending operation. Releases all resources
159 * of the operation and will ensure that no event
160 * is generated for the operation. Does NOT guarantee
161 * that the operation will be fully undone (or that
162 * nothing ever happened).
163 *
164 * @param operation operation to cancel
165 */
166void
167GNUNET_TESTBED_operation_cancel (struct GNUNET_TESTBED_Operation *operation)
168{
169 // test that operation had not yet generated an event
170 GNUNET_break (0);
171 operation_release (operation);
172}
173
174
175/**
176 * Signal that the information from an operation has been fully
177 * processed. This function MUST be called for each event
178 * of type 'operation_finished' to fully remove the operation
179 * from the operation queue. After calling this function, the
180 * 'op_result' becomes invalid (!).
181 *
182 * @param operation operation to signal completion for
183 */
184void 149void
185GNUNET_TESTBED_operation_done (struct GNUNET_TESTBED_Operation *operation) 150operation_release_ (struct GNUNET_TESTBED_Operation *operation)
186{ 151{
187 // test that operation was started and had generated an event 152 // call operation->release, remove from queues
188 GNUNET_break (0); 153 GNUNET_break (0);
189 operation_release (operation);
190} 154}
191 155
192 156
193
194/* end of testbed_api_operations.c */ 157/* end of testbed_api_operations.c */
diff --git a/src/testbed/testbed_api_operations.h b/src/testbed/testbed_api_operations.h
index 4c888d52d..5edca152d 100644
--- a/src/testbed/testbed_api_operations.h
+++ b/src/testbed/testbed_api_operations.h
@@ -128,5 +128,15 @@ GNUNET_TESTBED_operation_create_ (void *cls,
128 ...); 128 ...);
129 129
130 130
131/**
132 * An operation is 'done' (was cancelled or finished); remove
133 * it from the queues and release associated resources.
134 *
135 * @param operation operation that finished
136 */
137void
138operation_release_ (struct GNUNET_TESTBED_Operation *operation);
139
140
131#endif 141#endif
132/* end of testbed_api_operations.h */ 142/* end of testbed_api_operations.h */
diff --git a/src/testbed/testbed_api_peers.c b/src/testbed/testbed_api_peers.c
index c2bf2107f..4711aba7d 100644
--- a/src/testbed/testbed_api_peers.c
+++ b/src/testbed/testbed_api_peers.c
@@ -103,6 +103,7 @@ GNUNET_TESTBED_peer_create_with_id_ (uint32_t unique_id,
103 data->cls = cls; 103 data->cls = cls;
104 data->peer = peer; 104 data->peer = peer;
105 op = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Operation)); 105 op = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Operation));
106 op->controller = controller;
106 op->operation_id = controller->operation_counter++; 107 op->operation_id = controller->operation_counter++;
107 op->type = OP_PEER_CREATE; 108 op->type = OP_PEER_CREATE;
108 op->data = data; 109 op->data = data;
@@ -185,6 +186,7 @@ GNUNET_TESTBED_peer_start (struct GNUNET_TESTBED_Peer *peer)
185 186
186 op = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Operation)); 187 op = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Operation));
187 op->operation_id = peer->controller->operation_counter++; 188 op->operation_id = peer->controller->operation_counter++;
189 op->controller = peer->controller;
188 op->type = OP_PEER_START; 190 op->type = OP_PEER_START;
189 op->data = peer; 191 op->data = peer;
190 msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_PeerStartMessage)); 192 msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_PeerStartMessage));
@@ -215,6 +217,7 @@ GNUNET_TESTBED_peer_stop (struct GNUNET_TESTBED_Peer *peer)
215 217
216 op = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Operation)); 218 op = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Operation));
217 op->operation_id = peer->controller->operation_counter++; 219 op->operation_id = peer->controller->operation_counter++;
220 op->controller = peer->controller;
218 op->type = OP_PEER_STOP; 221 op->type = OP_PEER_STOP;
219 op->data = peer; 222 op->data = peer;
220 msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_PeerStopMessage)); 223 msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_PeerStopMessage));
@@ -251,6 +254,7 @@ GNUNET_TESTBED_peer_get_information (struct GNUNET_TESTBED_Peer *peer,
251 op = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Operation)); 254 op = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Operation));
252 op->type = OP_PEER_INFO; 255 op->type = OP_PEER_INFO;
253 op->operation_id = peer->controller->operation_counter++; 256 op->operation_id = peer->controller->operation_counter++;
257 op->controller = peer->controller;
254 op->data = data; 258 op->data = data;
255 msg = GNUNET_malloc (sizeof (struct 259 msg = GNUNET_malloc (sizeof (struct
256 GNUNET_TESTBED_PeerGetConfigurationMessage)); 260 GNUNET_TESTBED_PeerGetConfigurationMessage));
@@ -304,6 +308,7 @@ GNUNET_TESTBED_peer_destroy (struct GNUNET_TESTBED_Peer *peer)
304 data->peer = peer; 308 data->peer = peer;
305 op = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Operation)); 309 op = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Operation));
306 op->operation_id = peer->controller->operation_counter++; 310 op->operation_id = peer->controller->operation_counter++;
311 op->controller = peer->controller;
307 op->type = OP_PEER_DESTROY; 312 op->type = OP_PEER_DESTROY;
308 op->data = data; 313 op->data = data;
309 msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_PeerDestroyMessage)); 314 msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_PeerDestroyMessage));
diff --git a/src/testbed/testbed_api_peers.h b/src/testbed/testbed_api_peers.h
index 5b0a23c64..b3a74eef7 100644
--- a/src/testbed/testbed_api_peers.h
+++ b/src/testbed/testbed_api_peers.h
@@ -133,6 +133,34 @@ struct PeerInfoData
133 133
134 134
135/** 135/**
136 * Data for the OperationType OP_PEER_INFO
137 */
138struct PeerInfoData2
139{
140 /**
141 * The type of peer information requested
142 */
143 enum GNUNET_TESTBED_PeerInformationType pit;
144
145 /**
146 * The data from reply
147 */
148 union
149 {
150 /**
151 * Configuration handle
152 */
153 struct GNUNET_CONFIGURATION_Handle *cfg;
154
155 /**
156 * Peer Identity
157 */
158 struct GNUNET_PeerIdentity *peer_identity;
159 } details;
160};
161
162
163/**
136 * Create the given peer at the specified host using the given 164 * Create the given peer at the specified host using the given
137 * controller. If the given controller is not running on the target 165 * controller. If the given controller is not running on the target
138 * host, it should find or create a controller at the target host and 166 * host, it should find or create a controller at the target host and