diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2012-07-25 09:59:10 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2012-07-25 09:59:10 +0000 |
commit | 8fcba4447fd83577ec94e5926801c396cf7dbaf8 (patch) | |
tree | 8a622ce8313dc0fdc638e17ff30a4e7df34aefab /src/testbed/testbed_api_hosts.c | |
parent | 90da8ec92541c5a645ada39ba524198f131ce6e5 (diff) | |
download | gnunet-8fcba4447fd83577ec94e5926801c396cf7dbaf8.tar.gz gnunet-8fcba4447fd83577ec94e5926801c396cf7dbaf8.zip |
-fixes mem leaks
Diffstat (limited to 'src/testbed/testbed_api_hosts.c')
-rw-r--r-- | src/testbed/testbed_api_hosts.c | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/src/testbed/testbed_api_hosts.c b/src/testbed/testbed_api_hosts.c index 066f0a254..b4a083366 100644 --- a/src/testbed/testbed_api_hosts.c +++ b/src/testbed/testbed_api_hosts.c | |||
@@ -235,6 +235,7 @@ GNUNET_TESTBED_host_create_with_id (uint32_t id, | |||
235 | uint16_t port) | 235 | uint16_t port) |
236 | { | 236 | { |
237 | struct GNUNET_TESTBED_Host *host; | 237 | struct GNUNET_TESTBED_Host *host; |
238 | uint32_t new_size; | ||
238 | 239 | ||
239 | if ((id < host_list_size) && (NULL != host_list[id])) | 240 | if ((id < host_list_size) && (NULL != host_list[id])) |
240 | { | 241 | { |
@@ -246,13 +247,17 @@ GNUNET_TESTBED_host_create_with_id (uint32_t id, | |||
246 | host->username = username; | 247 | host->username = username; |
247 | host->id = id; | 248 | host->id = id; |
248 | host->port = (0 == port) ? 22 : port; | 249 | host->port = (0 == port) ? 22 : port; |
249 | if (id >= host_list_size) | 250 | new_size = host_list_size; |
251 | while (id >= new_size) | ||
252 | new_size += HOST_LIST_GROW_STEP; | ||
253 | if (new_size != host_list_size) | ||
250 | { | 254 | { |
251 | host_list_size += HOST_LIST_GROW_STEP; | ||
252 | host_list = GNUNET_realloc (host_list, sizeof (struct GNUNET_TESTBED_Host) | 255 | host_list = GNUNET_realloc (host_list, sizeof (struct GNUNET_TESTBED_Host) |
253 | * host_list_size); | 256 | * new_size); |
254 | (void) memset(&host_list[host_list_size - HOST_LIST_GROW_STEP], | 257 | (void) memset(&host_list[host_list_size], 0, |
255 | 0, sizeof (struct GNUNET_TESTBED_Host) * host_list_size); | 258 | sizeof (struct GNUNET_TESTBED_Host) * |
259 | (new_size - host_list_size)); | ||
260 | host_list_size = new_size; | ||
256 | } | 261 | } |
257 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 262 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
258 | "Adding host with id: %u\n", host->id); | 263 | "Adding host with id: %u\n", host->id); |
@@ -322,18 +327,21 @@ GNUNET_TESTBED_host_destroy (struct GNUNET_TESTBED_Host *host) | |||
322 | GNUNET_CONTAINER_DLL_remove (host->rc_head, host->rc_tail, rc); | 327 | GNUNET_CONTAINER_DLL_remove (host->rc_head, host->rc_tail, rc); |
323 | GNUNET_free (rc); | 328 | GNUNET_free (rc); |
324 | } | 329 | } |
325 | for (id = 0; id < HOST_LIST_GROW_STEP; id++) | 330 | GNUNET_free (host); |
331 | while (host_list_size >= HOST_LIST_GROW_STEP) | ||
326 | { | 332 | { |
327 | if (((host->id + id) >= host_list_size) || | 333 | for (id = host_list_size - 1; |
328 | (NULL != host_list[host->id + id])) | 334 | id > host_list_size - HOST_LIST_GROW_STEP; id--) |
335 | if (NULL != host_list[id]) | ||
336 | break; | ||
337 | if (id != host_list_size - HOST_LIST_GROW_STEP) | ||
338 | break; | ||
339 | if (NULL != host_list[id]) | ||
329 | break; | 340 | break; |
330 | } | ||
331 | if (HOST_LIST_GROW_STEP == id) | ||
332 | { | ||
333 | host_list_size -= HOST_LIST_GROW_STEP; | 341 | host_list_size -= HOST_LIST_GROW_STEP; |
334 | host_list = GNUNET_realloc (host_list, host_list_size); | ||
335 | } | 342 | } |
336 | GNUNET_free (host); | 343 | host_list = GNUNET_realloc (host_list, sizeof (struct GNUNET_TESTBED_Host) * |
344 | host_list_size); | ||
337 | } | 345 | } |
338 | 346 | ||
339 | 347 | ||