forked from pi-hole/FTL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflush.c
89 lines (76 loc) · 2 KB
/
flush.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/* Pi-hole: A black hole for Internet advertisements
* (c) 2017 Pi-hole, LLC (https://pi-hole.net)
* Network-wide ad blocking via your own hardware.
*
* FTL Engine
* Log flush handling routines
*
* This file is copyright under the latest version of the EUPL.
* Please see LICENSE file for your rights under this license. */
#include "FTL.h"
void pihole_log_flushed(bool message)
{
if(message)
{
logg("NOTICE: pihole.log has been flushed");
logg(" Resetting internal data structure");
logg(" Queries in memory before flushing: %i",counters.queries);
}
int i;
// Free memory on allocated data structure
// queries struct: No allocated entries
free(queries);
queries = NULL;
// forwarded struct: Free allocated substructure
for(i=0;i<counters.forwarded;i++)
{
free(forwarded[i].name);
free(forwarded[i].ip);
}
free(forwarded);
forwarded = NULL;
// clients struct: Free allocated substructure
for(i=0;i<counters.clients;i++)
{
free(clients[i].name);
free(clients[i].ip);
}
free(clients);
clients = NULL;
// domains struct: Free allocated substructure
for(i=0;i<counters.domains;i++)
{
free(domains[i].domain);
}
free(domains);
domains = NULL;
memory.domainnames = 0;
// wildcarddomains struct: Free allocated substructure
for(i=0;i<counters.wildcarddomains;i++)
{
free(wildcarddomains[i]);
}
free(wildcarddomains);
wildcarddomains = NULL;
memory.wildcarddomains = 0;
// overTime struct: Free allocated substructure
for(i=0;i<counters.overTime;i++)
{
if(overTime[i].forwarddata != NULL )
free(overTime[i].forwarddata);
free(overTime[i].querytypedata);
}
free(overTime);
overTime = NULL;
memory.forwarddata = 0;
memory.querytypedata = 0;
// Reset DB index counter so that new queries will be stored in the DB
lastdbindex = 0;
// Reset all counters to zero
memset(&counters, 0, sizeof(countersStruct));
// Recount entries in gravity files
read_gravity_files();
// Try to import queries from long-term database if available
if(database)
read_data_from_DB();
}