Free allocated memory on exit
This should reduce the number of possible memory leaks reported by valgrind. The remaining reported leaks are sched tqe allocation, async DNS instance allocation, cmdmon response/timestamp cell allocation, and clientlog subnet allocation.
This commit is contained in:
parent
d466390233
commit
f6ed7844e1
13 changed files with 116 additions and 9 deletions
|
@ -174,6 +174,11 @@ CLG_Initialise(void)
|
|||
void
|
||||
CLG_Finalise(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < n_nodes; i++)
|
||||
Free(nodes[i]);
|
||||
Free(nodes);
|
||||
}
|
||||
|
||||
/* ================================================== */
|
||||
|
|
45
conf.c
45
conf.c
|
@ -78,7 +78,7 @@ static void parse_tempcomp(char *);
|
|||
|
||||
static int restarted = 0;
|
||||
static int generate_command_key = 0;
|
||||
static char *rtc_device = "/dev/rtc";
|
||||
static char *rtc_device;
|
||||
static int acquisition_port = -1;
|
||||
static int ntp_port = 123;
|
||||
static char *keys_file = NULL;
|
||||
|
@ -104,8 +104,8 @@ static int do_log_refclocks = 0;
|
|||
static int do_log_tempcomp = 0;
|
||||
static int do_dump_on_exit = 0;
|
||||
static int log_banner = 32;
|
||||
static char *logdir = ".";
|
||||
static char *dumpdir = ".";
|
||||
static char *logdir;
|
||||
static char *dumpdir;
|
||||
|
||||
static int enable_local=0;
|
||||
static int local_stratum;
|
||||
|
@ -180,7 +180,7 @@ static IPAddr bind_cmd_address4, bind_cmd_address6;
|
|||
|
||||
/* Filename to use for storing pid of running chronyd, to prevent multiple
|
||||
* chronyds being started. */
|
||||
static char *pidfile = "/var/run/chronyd.pid";
|
||||
static char *pidfile;
|
||||
|
||||
/* Temperature sensor, update interval and compensation coefficients */
|
||||
static char *tempcomp_file = NULL;
|
||||
|
@ -194,7 +194,7 @@ static int lock_memory = 0;
|
|||
static char *leapsec_tz = NULL;
|
||||
|
||||
/* Name of the user to which will be dropped root privileges. */
|
||||
static char *user = DEFAULT_USER;
|
||||
static char *user;
|
||||
|
||||
typedef struct {
|
||||
NTP_Source_Type type;
|
||||
|
@ -286,9 +286,39 @@ check_number_of_args(char *line, int num)
|
|||
/* ================================================== */
|
||||
|
||||
void
|
||||
CNF_SetRestarted(int r)
|
||||
CNF_Initialise(int r)
|
||||
{
|
||||
restarted = r;
|
||||
|
||||
dumpdir = Strdup(".");
|
||||
logdir = Strdup(".");
|
||||
pidfile = Strdup("/var/run/chronyd.pid");
|
||||
rtc_device = Strdup("/dev/rtc");
|
||||
user = Strdup(DEFAULT_USER);
|
||||
}
|
||||
|
||||
/* ================================================== */
|
||||
|
||||
void
|
||||
CNF_Finalise(void)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < n_ntp_sources; i++)
|
||||
Free(ntp_sources[i].params.name);
|
||||
|
||||
Free(drift_file);
|
||||
Free(dumpdir);
|
||||
Free(hwclock_file);
|
||||
Free(keys_file);
|
||||
Free(leapsec_tz);
|
||||
Free(logdir);
|
||||
Free(pidfile);
|
||||
Free(rtc_device);
|
||||
Free(rtc_file);
|
||||
Free(user);
|
||||
Free(mail_user_on_change);
|
||||
Free(tempcomp_file);
|
||||
}
|
||||
|
||||
/* ================================================== */
|
||||
|
@ -462,6 +492,7 @@ static int
|
|||
parse_string(char *line, char **result)
|
||||
{
|
||||
check_number_of_args(line, 1);
|
||||
Free(*result);
|
||||
*result = Strdup(line);
|
||||
return 1;
|
||||
}
|
||||
|
@ -856,6 +887,7 @@ parse_mailonchange(char *line)
|
|||
check_number_of_args(line, 2);
|
||||
address = line;
|
||||
line = CPS_SplitWord(line);
|
||||
Free(mail_user_on_change);
|
||||
if (sscanf(line, "%lf", &mail_change_threshold) == 1) {
|
||||
mail_user_on_change = Strdup(address);
|
||||
} else {
|
||||
|
@ -1139,6 +1171,7 @@ parse_tempcomp(char *line)
|
|||
return;
|
||||
}
|
||||
|
||||
Free(tempcomp_file);
|
||||
tempcomp_file = Strdup(p);
|
||||
}
|
||||
|
||||
|
|
3
conf.h
3
conf.h
|
@ -30,7 +30,8 @@
|
|||
|
||||
#include "addressing.h"
|
||||
|
||||
extern void CNF_SetRestarted(int);
|
||||
extern void CNF_Initialise(int restarted);
|
||||
extern void CNF_Finalise(void);
|
||||
|
||||
extern char *CNF_GetRtcDevice(void);
|
||||
|
||||
|
|
2
hash.h
2
hash.h
|
@ -38,4 +38,6 @@ extern unsigned int HSH_Hash(int id,
|
|||
const unsigned char *in2, unsigned int in2_len,
|
||||
unsigned char *out, unsigned int out_len);
|
||||
|
||||
extern void HSH_Finalise(void);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -62,3 +62,8 @@ HSH_Hash(int id, const unsigned char *in1, unsigned int in1_len,
|
|||
|
||||
return 16;
|
||||
}
|
||||
|
||||
void
|
||||
HSH_Finalise(void)
|
||||
{
|
||||
}
|
||||
|
|
14
hash_nss.c
14
hash_nss.c
|
@ -87,3 +87,17 @@ HSH_Hash(int id, const unsigned char *in1, unsigned int in1_len,
|
|||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void
|
||||
HSH_Finalise(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; hashes[i].name; i++) {
|
||||
if (hashes[i].context)
|
||||
NSSLOWHASH_Destroy(hashes[i].context);
|
||||
}
|
||||
|
||||
if (ictx)
|
||||
NSSLOW_Shutdown(ictx);
|
||||
}
|
||||
|
|
|
@ -114,3 +114,8 @@ HSH_Hash(int id, const unsigned char *in1, unsigned int in1_len,
|
|||
|
||||
return len;
|
||||
}
|
||||
|
||||
void
|
||||
HSH_Finalise(void)
|
||||
{
|
||||
}
|
||||
|
|
5
keys.c
5
keys.c
|
@ -137,6 +137,11 @@ KEY_Initialise(void)
|
|||
void
|
||||
KEY_Finalise(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i=0; i<n_keys; i++) {
|
||||
Free(keys[i].val);
|
||||
}
|
||||
}
|
||||
|
||||
/* ================================================== */
|
||||
|
|
7
local.c
7
local.c
|
@ -168,6 +168,13 @@ LCL_Initialise(void)
|
|||
void
|
||||
LCL_Finalise(void)
|
||||
{
|
||||
while (change_list.next != &change_list)
|
||||
LCL_RemoveParameterChangeHandler(change_list.next->handler,
|
||||
change_list.next->anything);
|
||||
|
||||
while (dispersion_notify_list.next != &dispersion_notify_list)
|
||||
LCL_RemoveDispersionNotifyHandler(dispersion_notify_list.next->handler,
|
||||
dispersion_notify_list.next->anything);
|
||||
}
|
||||
|
||||
/* ================================================== */
|
||||
|
|
10
main.c
10
main.c
|
@ -86,6 +86,9 @@ MAI_CleanupAndExit(void)
|
|||
SRC_DumpSources();
|
||||
}
|
||||
|
||||
/* Don't update clock when removing sources */
|
||||
REF_SetMode(REF_ModeIgnore);
|
||||
|
||||
TMC_Finalise();
|
||||
MNL_Finalise();
|
||||
CLG_Finalise();
|
||||
|
@ -93,10 +96,10 @@ MAI_CleanupAndExit(void)
|
|||
NCR_Finalise();
|
||||
BRD_Finalise();
|
||||
SST_Finalise();
|
||||
REF_Finalise();
|
||||
KEY_Finalise();
|
||||
RCL_Finalise();
|
||||
SRC_Finalise();
|
||||
REF_Finalise();
|
||||
RTC_Finalise();
|
||||
CAM_Finalise();
|
||||
NIO_Finalise();
|
||||
|
@ -106,8 +109,11 @@ MAI_CleanupAndExit(void)
|
|||
|
||||
delete_pidfile();
|
||||
|
||||
CNF_Finalise();
|
||||
LOG_Finalise();
|
||||
|
||||
HSH_Finalise();
|
||||
|
||||
exit(exit_status);
|
||||
}
|
||||
|
||||
|
@ -430,7 +436,7 @@ int main
|
|||
|
||||
DNS_SetAddressFamily(address_family);
|
||||
|
||||
CNF_SetRestarted(restarted);
|
||||
CNF_Initialise(restarted);
|
||||
|
||||
/* Parse the config file or the remaining command line arguments */
|
||||
if (!config_args) {
|
||||
|
|
|
@ -122,6 +122,23 @@ NSR_Initialise(void)
|
|||
void
|
||||
NSR_Finalise(void)
|
||||
{
|
||||
int i;
|
||||
struct UnresolvedSource *us;
|
||||
|
||||
for (i = 0; i < N_RECORDS; i++) {
|
||||
if (!records[i].remote_addr)
|
||||
continue;
|
||||
records[i].remote_addr = NULL;
|
||||
NCR_DestroyInstance(records[i].data);
|
||||
}
|
||||
|
||||
while (unresolved_sources) {
|
||||
us = unresolved_sources;
|
||||
unresolved_sources = us->next;
|
||||
Free(us->name);
|
||||
Free(us);
|
||||
}
|
||||
|
||||
initialised = 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -140,6 +140,7 @@ RCL_Finalise(void)
|
|||
|
||||
filter_fini(&inst->filter);
|
||||
Free(inst->driver_parameter);
|
||||
SRC_DestroyInstance(inst->source);
|
||||
}
|
||||
|
||||
if (n_sources > 0) {
|
||||
|
|
|
@ -165,6 +165,7 @@ source_to_string(SRC_Instance inst);
|
|||
void SRC_Initialise(void) {
|
||||
sources = NULL;
|
||||
sort_list = NULL;
|
||||
sel_sources = NULL;
|
||||
n_sources = 0;
|
||||
max_n_sources = 0;
|
||||
selected_source_index = INVALID_SOURCE;
|
||||
|
@ -183,6 +184,11 @@ void SRC_Finalise(void)
|
|||
{
|
||||
LCL_RemoveParameterChangeHandler(slew_sources, NULL);
|
||||
LCL_RemoveDispersionNotifyHandler(add_dispersion, NULL);
|
||||
|
||||
Free(sources);
|
||||
Free(sort_list);
|
||||
Free(sel_sources);
|
||||
|
||||
initialised = 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue