[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r31390 - gnunet/src/util
From: |
gnunet |
Subject: |
[GNUnet-SVN] r31390 - gnunet/src/util |
Date: |
Sun, 15 Dec 2013 00:43:20 +0100 |
Author: grothoff
Date: 2013-12-15 00:43:20 +0100 (Sun, 15 Dec 2013)
New Revision: 31390
Modified:
gnunet/src/util/program.c
gnunet/src/util/speedup.c
Log:
-fixing leaks on error paths
Modified: gnunet/src/util/program.c
===================================================================
--- gnunet/src/util/program.c 2013-12-14 12:50:01 UTC (rev 31389)
+++ gnunet/src/util/program.c 2013-12-14 23:43:20 UTC (rev 31390)
@@ -1,6 +1,6 @@
/*
This file is part of GNUnet.
- (C) 2009 Christian Grothoff (and other contributing authors)
+ (C) 2009-2013 Christian Grothoff (and other contributing authors)
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
@@ -55,7 +55,7 @@
GNUNET_PROGRAM_Main task;
/**
- * Closure for task.
+ * Closure for @e task.
*/
void *task_cls;
@@ -66,9 +66,20 @@
};
+
+/**
+ * Start task that may speed up our system clock artificially
+ *
+ * @param cfg configuration to use
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR if the speedup was not
configured
+ */
int
GNUNET_SPEEDUP_start_ (const struct GNUNET_CONFIGURATION_Handle *cfg);
+
+/**
+ * Stop tasks that modify clock behavior.
+ */
int
GNUNET_SPEEDUP_stop_ (void);
@@ -121,16 +132,16 @@
* Run a standard GNUnet command startup sequence (initialize loggers
* and configuration, parse options).
*
- * @param argc number of command line arguments
+ * @param argc number of command line arguments in @a argv
* @param argv command line arguments
* @param binaryName our expected name
* @param binaryHelp help text for the program
* @param options command line options
* @param task main function to run
- * @param task_cls closure for task
- * @param run_without_scheduler GNUNET_NO start the scheduler, GNUNET_YES do
not
+ * @param task_cls closure for @a task
+ * @param run_without_scheduler #GNUNET_NO start the scheduler, #GNUNET_YES do
not
* start the scheduler just run the main task
- * @return GNUNET_SYSERR on error, GNUNET_OK on success
+ * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
*/
int
GNUNET_PROGRAM_run2 (int argc, char *const *argv, const char *binaryName,
@@ -168,7 +179,7 @@
logfile = NULL;
gargs = getenv ("GNUNET_ARGS");
- if (gargs != NULL)
+ if (NULL != gargs)
{
char **gargv;
unsigned int gargc;
@@ -181,12 +192,8 @@
for (i = 0; i < argc; i++)
GNUNET_array_append (gargv, gargc, GNUNET_strdup (argv[i]));
cargs = GNUNET_strdup (gargs);
- tok = strtok (cargs, " ");
- while (NULL != tok)
- {
+ for (tok = strtok (cargs, " "); NULL != tok; tok = strtok (NULL, " "))
GNUNET_array_append (gargv, gargc, GNUNET_strdup (tok));
- tok = strtok (NULL, " ");
- }
GNUNET_free (cargs);
GNUNET_array_append (gargv, gargc, NULL);
argv = (char *const *) gargv;
@@ -201,7 +208,7 @@
#if ENABLE_NLS
setlocale (LC_ALL, "");
path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LOCALEDIR);
- if (path != NULL)
+ if (NULL != path)
{
BINDTEXTDOMAIN ("GNUnet", path);
GNUNET_free (path);
@@ -209,7 +216,7 @@
textdomain ("GNUnet");
#endif
cnt = 0;
- while (options[cnt].name != NULL)
+ while (NULL != options[cnt].name)
cnt++;
allopts =
GNUNET_malloc ((cnt +
@@ -240,14 +247,9 @@
if ((GNUNET_OK > ret) ||
(GNUNET_OK != GNUNET_log_setup (lpfx, loglev, logfile)))
{
- GNUNET_CONFIGURATION_destroy (cfg);
- GNUNET_free_non_null (cc.cfgfile);
- GNUNET_free_non_null (loglev);
- GNUNET_free_non_null (logfile);
- GNUNET_free (cfg_fn);
GNUNET_free (allopts);
GNUNET_free (lpfx);
- return (ret == GNUNET_SYSERR) ? GNUNET_SYSERR : GNUNET_OK;
+ goto cleanup;
}
if (NULL == cc.cfgfile)
cc.cfgfile = GNUNET_strdup (cfg_fn);
@@ -259,8 +261,10 @@
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_("Malformed configuration file `%s', exit ...\n"),
cc.cfgfile);
- GNUNET_free (cc.cfgfile);
- return GNUNET_SYSERR;
+ ret = GNUNET_SYSERR;
+ GNUNET_free (allopts);
+ GNUNET_free (lpfx);
+ goto cleanup;
}
}
else
@@ -273,8 +277,10 @@
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_("Malformed configuration, exit ...\n"));
- GNUNET_free (cc.cfgfile);
- return GNUNET_SYSERR;
+ ret = GNUNET_SYSERR;
+ GNUNET_free (allopts);
+ GNUNET_free (lpfx);
+ goto cleanup;
}
}
GNUNET_free (allopts);
@@ -293,21 +299,22 @@
cc.args = &argv[ret];
if (GNUNET_NO == run_without_scheduler)
{
- GNUNET_SCHEDULER_run (&program_main, &cc);
+ GNUNET_SCHEDULER_run (&program_main, &cc);
}
else
{
- GNUNET_RESOLVER_connect (cc.cfg);
- cc.task (cc.task_cls, cc.args, cc.cfgfile, cc.cfg);
+ GNUNET_RESOLVER_connect (cc.cfg);
+ cc.task (cc.task_cls, cc.args, cc.cfgfile, cc.cfg);
}
- /* clean up */
+ ret = GNUNET_OK;
+ cleanup:
GNUNET_SPEEDUP_stop_ ();
GNUNET_CONFIGURATION_destroy (cfg);
- GNUNET_free (cc.cfgfile);
+ GNUNET_free_non_null (cc.cfgfile);
GNUNET_free (cfg_fn);
GNUNET_free_non_null (loglev);
GNUNET_free_non_null (logfile);
- return GNUNET_OK;
+ return ret;
}
/**
@@ -324,14 +331,19 @@
* @return #GNUNET_SYSERR on error, #GNUNET_OK on success
*/
int
-GNUNET_PROGRAM_run (int argc, char *const *argv, const char *binaryName,
+GNUNET_PROGRAM_run (int argc, char *const *argv,
+ const char *binaryName,
const char *binaryHelp,
const struct GNUNET_GETOPT_CommandLineOption *options,
- GNUNET_PROGRAM_Main task, void *task_cls)
+ GNUNET_PROGRAM_Main task,
+ void *task_cls)
{
- return GNUNET_PROGRAM_run2 (argc, argv, binaryName, binaryHelp,
options, task, task_cls, GNUNET_NO);
+ return GNUNET_PROGRAM_run2 (argc, argv,
+ binaryName, binaryHelp,
+ options,
+ task, task_cls,
+ GNUNET_NO);
}
-
/* end of program.c */
Modified: gnunet/src/util/speedup.c
===================================================================
--- gnunet/src/util/speedup.c 2013-12-14 12:50:01 UTC (rev 31389)
+++ gnunet/src/util/speedup.c 2013-12-14 23:43:20 UTC (rev 31390)
@@ -37,7 +37,8 @@
static void
-do_speedup (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+do_speedup (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
{
static long long current_offset;
@@ -57,14 +58,18 @@
* Start task that may speed up our system clock artificially
*
* @param cfg configuration to use
- * @return GNUNET_OK on success, GNUNET_SYSERR if the speedup was not
configured
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR if the speedup was not
configured
*/
int
GNUNET_SPEEDUP_start_ (const struct GNUNET_CONFIGURATION_Handle *cfg)
{
- if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time (cfg, "testing",
"SPEEDUP_INTERVAL", &interval))
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_time (cfg, "testing",
+ "SPEEDUP_INTERVAL", &interval))
return GNUNET_SYSERR;
- if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time (cfg, "testing",
"SPEEDUP_DELTA", &delta))
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_time (cfg, "testing",
+ "SPEEDUP_DELTA", &delta))
return GNUNET_SYSERR;
if ((0 == interval.rel_value_us) || (0 == delta.rel_value_us))
@@ -79,7 +84,8 @@
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Speed up executed every %s\n",
GNUNET_STRINGS_relative_time_to_string (interval, GNUNET_NO));
- speedup_task = GNUNET_SCHEDULER_add_now_with_lifeness (GNUNET_NO,
&do_speedup, NULL);
+ speedup_task = GNUNET_SCHEDULER_add_now_with_lifeness (GNUNET_NO,
+ &do_speedup, NULL);
return GNUNET_OK;
}
@@ -88,7 +94,7 @@
* Stop tasks that modify clock behavior.
*/
void
-GNUNET_SPEEDUP_stop_ ( )
+GNUNET_SPEEDUP_stop_ ()
{
if (GNUNET_SCHEDULER_NO_TASK != speedup_task)
{
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r31390 - gnunet/src/util,
gnunet <=