aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-12-14 23:43:20 +0000
committerChristian Grothoff <christian@grothoff.org>2013-12-14 23:43:20 +0000
commit397d2a489f6af963ec63f8f5473469e46b7619f4 (patch)
treee88834f74b809be41c3d24a4b78f4bc2c2bfb631 /src
parentcc81eac80185a80edec6208fba6961cb392a53b8 (diff)
downloadgnunet-397d2a489f6af963ec63f8f5473469e46b7619f4.tar.gz
gnunet-397d2a489f6af963ec63f8f5473469e46b7619f4.zip
-fixing leaks on error paths
Diffstat (limited to 'src')
-rw-r--r--src/util/program.c80
-rw-r--r--src/util/speedup.c18
2 files changed, 58 insertions, 40 deletions
diff --git a/src/util/program.c b/src/util/program.c
index 3f8708f7d..1c32ec500 100644
--- a/src/util/program.c
+++ b/src/util/program.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 (C) 2009 Christian Grothoff (and other contributing authors) 3 (C) 2009-2013 Christian Grothoff (and other contributing authors)
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -55,7 +55,7 @@ struct CommandContext
55 GNUNET_PROGRAM_Main task; 55 GNUNET_PROGRAM_Main task;
56 56
57 /** 57 /**
58 * Closure for task. 58 * Closure for @e task.
59 */ 59 */
60 void *task_cls; 60 void *task_cls;
61 61
@@ -66,9 +66,20 @@ struct CommandContext
66 66
67}; 67};
68 68
69
70/**
71 * Start task that may speed up our system clock artificially
72 *
73 * @param cfg configuration to use
74 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the speedup was not configured
75 */
69int 76int
70GNUNET_SPEEDUP_start_ (const struct GNUNET_CONFIGURATION_Handle *cfg); 77GNUNET_SPEEDUP_start_ (const struct GNUNET_CONFIGURATION_Handle *cfg);
71 78
79
80/**
81 * Stop tasks that modify clock behavior.
82 */
72int 83int
73GNUNET_SPEEDUP_stop_ (void); 84GNUNET_SPEEDUP_stop_ (void);
74 85
@@ -121,16 +132,16 @@ cmd_sorter (const void *a1, const void *a2)
121 * Run a standard GNUnet command startup sequence (initialize loggers 132 * Run a standard GNUnet command startup sequence (initialize loggers
122 * and configuration, parse options). 133 * and configuration, parse options).
123 * 134 *
124 * @param argc number of command line arguments 135 * @param argc number of command line arguments in @a argv
125 * @param argv command line arguments 136 * @param argv command line arguments
126 * @param binaryName our expected name 137 * @param binaryName our expected name
127 * @param binaryHelp help text for the program 138 * @param binaryHelp help text for the program
128 * @param options command line options 139 * @param options command line options
129 * @param task main function to run 140 * @param task main function to run
130 * @param task_cls closure for task 141 * @param task_cls closure for @a task
131 * @param run_without_scheduler GNUNET_NO start the scheduler, GNUNET_YES do not 142 * @param run_without_scheduler #GNUNET_NO start the scheduler, #GNUNET_YES do not
132 * start the scheduler just run the main task 143 * start the scheduler just run the main task
133 * @return GNUNET_SYSERR on error, GNUNET_OK on success 144 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
134 */ 145 */
135int 146int
136GNUNET_PROGRAM_run2 (int argc, char *const *argv, const char *binaryName, 147GNUNET_PROGRAM_run2 (int argc, char *const *argv, const char *binaryName,
@@ -168,7 +179,7 @@ GNUNET_PROGRAM_run2 (int argc, char *const *argv, const char *binaryName,
168 179
169 logfile = NULL; 180 logfile = NULL;
170 gargs = getenv ("GNUNET_ARGS"); 181 gargs = getenv ("GNUNET_ARGS");
171 if (gargs != NULL) 182 if (NULL != gargs)
172 { 183 {
173 char **gargv; 184 char **gargv;
174 unsigned int gargc; 185 unsigned int gargc;
@@ -181,12 +192,8 @@ GNUNET_PROGRAM_run2 (int argc, char *const *argv, const char *binaryName,
181 for (i = 0; i < argc; i++) 192 for (i = 0; i < argc; i++)
182 GNUNET_array_append (gargv, gargc, GNUNET_strdup (argv[i])); 193 GNUNET_array_append (gargv, gargc, GNUNET_strdup (argv[i]));
183 cargs = GNUNET_strdup (gargs); 194 cargs = GNUNET_strdup (gargs);
184 tok = strtok (cargs, " "); 195 for (tok = strtok (cargs, " "); NULL != tok; tok = strtok (NULL, " "))
185 while (NULL != tok)
186 {
187 GNUNET_array_append (gargv, gargc, GNUNET_strdup (tok)); 196 GNUNET_array_append (gargv, gargc, GNUNET_strdup (tok));
188 tok = strtok (NULL, " ");
189 }
190 GNUNET_free (cargs); 197 GNUNET_free (cargs);
191 GNUNET_array_append (gargv, gargc, NULL); 198 GNUNET_array_append (gargv, gargc, NULL);
192 argv = (char *const *) gargv; 199 argv = (char *const *) gargv;
@@ -201,7 +208,7 @@ GNUNET_PROGRAM_run2 (int argc, char *const *argv, const char *binaryName,
201#if ENABLE_NLS 208#if ENABLE_NLS
202 setlocale (LC_ALL, ""); 209 setlocale (LC_ALL, "");
203 path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LOCALEDIR); 210 path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LOCALEDIR);
204 if (path != NULL) 211 if (NULL != path)
205 { 212 {
206 BINDTEXTDOMAIN ("GNUnet", path); 213 BINDTEXTDOMAIN ("GNUnet", path);
207 GNUNET_free (path); 214 GNUNET_free (path);
@@ -209,7 +216,7 @@ GNUNET_PROGRAM_run2 (int argc, char *const *argv, const char *binaryName,
209 textdomain ("GNUnet"); 216 textdomain ("GNUnet");
210#endif 217#endif
211 cnt = 0; 218 cnt = 0;
212 while (options[cnt].name != NULL) 219 while (NULL != options[cnt].name)
213 cnt++; 220 cnt++;
214 allopts = 221 allopts =
215 GNUNET_malloc ((cnt + 222 GNUNET_malloc ((cnt +
@@ -240,14 +247,9 @@ GNUNET_PROGRAM_run2 (int argc, char *const *argv, const char *binaryName,
240 if ((GNUNET_OK > ret) || 247 if ((GNUNET_OK > ret) ||
241 (GNUNET_OK != GNUNET_log_setup (lpfx, loglev, logfile))) 248 (GNUNET_OK != GNUNET_log_setup (lpfx, loglev, logfile)))
242 { 249 {
243 GNUNET_CONFIGURATION_destroy (cfg);
244 GNUNET_free_non_null (cc.cfgfile);
245 GNUNET_free_non_null (loglev);
246 GNUNET_free_non_null (logfile);
247 GNUNET_free (cfg_fn);
248 GNUNET_free (allopts); 250 GNUNET_free (allopts);
249 GNUNET_free (lpfx); 251 GNUNET_free (lpfx);
250 return (ret == GNUNET_SYSERR) ? GNUNET_SYSERR : GNUNET_OK; 252 goto cleanup;
251 } 253 }
252 if (NULL == cc.cfgfile) 254 if (NULL == cc.cfgfile)
253 cc.cfgfile = GNUNET_strdup (cfg_fn); 255 cc.cfgfile = GNUNET_strdup (cfg_fn);
@@ -259,8 +261,10 @@ GNUNET_PROGRAM_run2 (int argc, char *const *argv, const char *binaryName,
259 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 261 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
260 _("Malformed configuration file `%s', exit ...\n"), 262 _("Malformed configuration file `%s', exit ...\n"),
261 cc.cfgfile); 263 cc.cfgfile);
262 GNUNET_free (cc.cfgfile); 264 ret = GNUNET_SYSERR;
263 return GNUNET_SYSERR; 265 GNUNET_free (allopts);
266 GNUNET_free (lpfx);
267 goto cleanup;
264 } 268 }
265 } 269 }
266 else 270 else
@@ -273,8 +277,10 @@ GNUNET_PROGRAM_run2 (int argc, char *const *argv, const char *binaryName,
273 { 277 {
274 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 278 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
275 _("Malformed configuration, exit ...\n")); 279 _("Malformed configuration, exit ...\n"));
276 GNUNET_free (cc.cfgfile); 280 ret = GNUNET_SYSERR;
277 return GNUNET_SYSERR; 281 GNUNET_free (allopts);
282 GNUNET_free (lpfx);
283 goto cleanup;
278 } 284 }
279 } 285 }
280 GNUNET_free (allopts); 286 GNUNET_free (allopts);
@@ -293,21 +299,22 @@ GNUNET_PROGRAM_run2 (int argc, char *const *argv, const char *binaryName,
293 cc.args = &argv[ret]; 299 cc.args = &argv[ret];
294 if (GNUNET_NO == run_without_scheduler) 300 if (GNUNET_NO == run_without_scheduler)
295 { 301 {
296 GNUNET_SCHEDULER_run (&program_main, &cc); 302 GNUNET_SCHEDULER_run (&program_main, &cc);
297 } 303 }
298 else 304 else
299 { 305 {
300 GNUNET_RESOLVER_connect (cc.cfg); 306 GNUNET_RESOLVER_connect (cc.cfg);
301 cc.task (cc.task_cls, cc.args, cc.cfgfile, cc.cfg); 307 cc.task (cc.task_cls, cc.args, cc.cfgfile, cc.cfg);
302 } 308 }
303 /* clean up */ 309 ret = GNUNET_OK;
310 cleanup:
304 GNUNET_SPEEDUP_stop_ (); 311 GNUNET_SPEEDUP_stop_ ();
305 GNUNET_CONFIGURATION_destroy (cfg); 312 GNUNET_CONFIGURATION_destroy (cfg);
306 GNUNET_free (cc.cfgfile); 313 GNUNET_free_non_null (cc.cfgfile);
307 GNUNET_free (cfg_fn); 314 GNUNET_free (cfg_fn);
308 GNUNET_free_non_null (loglev); 315 GNUNET_free_non_null (loglev);
309 GNUNET_free_non_null (logfile); 316 GNUNET_free_non_null (logfile);
310 return GNUNET_OK; 317 return ret;
311} 318}
312 319
313/** 320/**
@@ -324,14 +331,19 @@ GNUNET_PROGRAM_run2 (int argc, char *const *argv, const char *binaryName,
324 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success 331 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
325 */ 332 */
326int 333int
327GNUNET_PROGRAM_run (int argc, char *const *argv, const char *binaryName, 334GNUNET_PROGRAM_run (int argc, char *const *argv,
335 const char *binaryName,
328 const char *binaryHelp, 336 const char *binaryHelp,
329 const struct GNUNET_GETOPT_CommandLineOption *options, 337 const struct GNUNET_GETOPT_CommandLineOption *options,
330 GNUNET_PROGRAM_Main task, void *task_cls) 338 GNUNET_PROGRAM_Main task,
339 void *task_cls)
331{ 340{
332 return GNUNET_PROGRAM_run2 (argc, argv, binaryName, binaryHelp, options, task, task_cls, GNUNET_NO); 341 return GNUNET_PROGRAM_run2 (argc, argv,
342 binaryName, binaryHelp,
343 options,
344 task, task_cls,
345 GNUNET_NO);
333} 346}
334 347
335 348
336
337/* end of program.c */ 349/* end of program.c */
diff --git a/src/util/speedup.c b/src/util/speedup.c
index 52ac3287c..c038c3858 100644
--- a/src/util/speedup.c
+++ b/src/util/speedup.c
@@ -37,7 +37,8 @@ static GNUNET_SCHEDULER_TaskIdentifier speedup_task;
37 37
38 38
39static void 39static void
40do_speedup (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 40do_speedup (void *cls,
41 const struct GNUNET_SCHEDULER_TaskContext *tc)
41{ 42{
42 static long long current_offset; 43 static long long current_offset;
43 44
@@ -57,14 +58,18 @@ do_speedup (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
57 * Start task that may speed up our system clock artificially 58 * Start task that may speed up our system clock artificially
58 * 59 *
59 * @param cfg configuration to use 60 * @param cfg configuration to use
60 * @return GNUNET_OK on success, GNUNET_SYSERR if the speedup was not configured 61 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the speedup was not configured
61 */ 62 */
62int 63int
63GNUNET_SPEEDUP_start_ (const struct GNUNET_CONFIGURATION_Handle *cfg) 64GNUNET_SPEEDUP_start_ (const struct GNUNET_CONFIGURATION_Handle *cfg)
64{ 65{
65 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time (cfg, "testing", "SPEEDUP_INTERVAL", &interval)) 66 if (GNUNET_OK !=
67 GNUNET_CONFIGURATION_get_value_time (cfg, "testing",
68 "SPEEDUP_INTERVAL", &interval))
66 return GNUNET_SYSERR; 69 return GNUNET_SYSERR;
67 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time (cfg, "testing", "SPEEDUP_DELTA", &delta)) 70 if (GNUNET_OK !=
71 GNUNET_CONFIGURATION_get_value_time (cfg, "testing",
72 "SPEEDUP_DELTA", &delta))
68 return GNUNET_SYSERR; 73 return GNUNET_SYSERR;
69 74
70 if ((0 == interval.rel_value_us) || (0 == delta.rel_value_us)) 75 if ((0 == interval.rel_value_us) || (0 == delta.rel_value_us))
@@ -79,7 +84,8 @@ GNUNET_SPEEDUP_start_ (const struct GNUNET_CONFIGURATION_Handle *cfg)
79 LOG (GNUNET_ERROR_TYPE_DEBUG, 84 LOG (GNUNET_ERROR_TYPE_DEBUG,
80 "Speed up executed every %s\n", 85 "Speed up executed every %s\n",
81 GNUNET_STRINGS_relative_time_to_string (interval, GNUNET_NO)); 86 GNUNET_STRINGS_relative_time_to_string (interval, GNUNET_NO));
82 speedup_task = GNUNET_SCHEDULER_add_now_with_lifeness (GNUNET_NO, &do_speedup, NULL); 87 speedup_task = GNUNET_SCHEDULER_add_now_with_lifeness (GNUNET_NO,
88 &do_speedup, NULL);
83 return GNUNET_OK; 89 return GNUNET_OK;
84} 90}
85 91
@@ -88,7 +94,7 @@ GNUNET_SPEEDUP_start_ (const struct GNUNET_CONFIGURATION_Handle *cfg)
88 * Stop tasks that modify clock behavior. 94 * Stop tasks that modify clock behavior.
89 */ 95 */
90void 96void
91GNUNET_SPEEDUP_stop_ ( ) 97GNUNET_SPEEDUP_stop_ ()
92{ 98{
93 if (GNUNET_SCHEDULER_NO_TASK != speedup_task) 99 if (GNUNET_SCHEDULER_NO_TASK != speedup_task)
94 { 100 {