aboutsummaryrefslogtreecommitdiff
path: root/src/testing
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2013-04-16 13:10:36 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2013-04-16 13:10:36 +0000
commitfb8e49e4048d013ffe0e3b05e8777f13dab8e571 (patch)
tree82f3d07d7e193fe75845143b0156dafbb510fb90 /src/testing
parentead89b2005376011111abab67088ed5cb475e200 (diff)
downloadgnunet-fb8e49e4048d013ffe0e3b05e8777f13dab8e571.tar.gz
gnunet-fb8e49e4048d013ffe0e3b05e8777f13dab8e571.zip
- close file fd after mapping the file
Diffstat (limited to 'src/testing')
-rw-r--r--src/testing/testing.c23
1 files changed, 10 insertions, 13 deletions
diff --git a/src/testing/testing.c b/src/testing/testing.c
index 14e660358..a1a2fdc06 100644
--- a/src/testing/testing.c
+++ b/src/testing/testing.c
@@ -97,11 +97,6 @@ struct GNUNET_TESTING_System
97 struct GNUNET_DISK_MapHandle *map; 97 struct GNUNET_DISK_MapHandle *map;
98 98
99 /** 99 /**
100 * File descriptor for the map.
101 */
102 struct GNUNET_DISK_FileHandle *map_fd;
103
104 /**
105 * Bitmap where each TCP port that has already been reserved for 100 * Bitmap where each TCP port that has already been reserved for
106 * some GNUnet peer is recorded. Note that we additionally need to 101 * some GNUnet peer is recorded. Note that we additionally need to
107 * test if a port is already in use by non-GNUnet components before 102 * test if a port is already in use by non-GNUnet components before
@@ -243,7 +238,8 @@ hostkeys_load (struct GNUNET_TESTING_System *system)
243 uint64_t fs; 238 uint64_t fs;
244 char *data_dir; 239 char *data_dir;
245 char *filename; 240 char *filename;
246 241 struct GNUNET_DISK_FileHandle *fd;
242
247 GNUNET_assert (NULL == system->hostkeys_data); 243 GNUNET_assert (NULL == system->hostkeys_data);
248 data_dir = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DATADIR); 244 data_dir = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DATADIR);
249 GNUNET_asprintf (&filename, "%s/testing_hostkeys.ecc", data_dir); 245 GNUNET_asprintf (&filename, "%s/testing_hostkeys.ecc", data_dir);
@@ -272,20 +268,23 @@ hostkeys_load (struct GNUNET_TESTING_System *system)
272 GNUNET_free (filename); 268 GNUNET_free (filename);
273 return GNUNET_SYSERR; 269 return GNUNET_SYSERR;
274 } 270 }
275 system->map_fd = GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READ, 271 fd = GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READ,
276 GNUNET_DISK_PERM_NONE); 272 GNUNET_DISK_PERM_NONE);
277 if (NULL == system->map_fd) 273 if (NULL == fd)
278 { 274 {
279 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", filename); 275 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", filename);
280 GNUNET_free (filename); 276 GNUNET_free (filename);
281 return GNUNET_SYSERR; 277 return GNUNET_SYSERR;
282 } 278 }
283 system->total_hostkeys = fs / GNUNET_TESTING_HOSTKEYFILESIZE; 279 GNUNET_free (filename);
284 system->hostkeys_data = GNUNET_DISK_file_map (system->map_fd, 280 system->hostkeys_data = GNUNET_DISK_file_map (fd,
285 &system->map, 281 &system->map,
286 GNUNET_DISK_MAP_TYPE_READ, 282 GNUNET_DISK_MAP_TYPE_READ,
287 fs); 283 fs);
288 GNUNET_free (filename); 284 GNUNET_DISK_file_close (fd);
285 if (NULL == system->hostkeys_data)
286 return GNUNET_SYSERR;
287 system->total_hostkeys = fs / GNUNET_TESTING_HOSTKEYFILESIZE;
289 return GNUNET_OK; 288 return GNUNET_OK;
290} 289}
291 290
@@ -302,8 +301,6 @@ hostkeys_unload (struct GNUNET_TESTING_System *system)
302 system->hostkeys_data = NULL; 301 system->hostkeys_data = NULL;
303 GNUNET_DISK_file_unmap (system->map); 302 GNUNET_DISK_file_unmap (system->map);
304 system->map = NULL; 303 system->map = NULL;
305 GNUNET_DISK_file_close (system->map_fd);
306 system->map_fd = NULL;
307 system->hostkeys_data = NULL; 304 system->hostkeys_data = NULL;
308 system->total_hostkeys = 0; 305 system->total_hostkeys = 0;
309} 306}