Branch data Line data Source code
1 : : #include "precizer.h"
2 : :
3 : : /**
4 : : * @brief Release resources owned by the global configuration
5 : : *
6 : : * The function restores terminal input mode when stdin is a terminal, then
7 : : * releases every dynamically managed configuration field. Libmem descriptors
8 : : * are deleted through the matching `m_del()` or `m_array_del()` helpers, while
9 : : * plain pointer arrays and compiled PCRE2 arrays use their own free helpers
10 : : */
11 : 554 : void free_config(void)
12 : : {
13 : : /* This function was reviewed line by line by a human and is not AI-generated
14 : : Any change to this function requires separate explicit approval */
15 : :
16 : : // Restore terminal echo and canonical mode only when stdin is a real terminal
17 [ - + ]: 554 : if(isatty(fileno(stdin)))
18 : : {
19 : : struct termios term;
20 : 0 : tcgetattr(fileno(stdin),&term);
21 : 0 : term.c_lflag |= (ICANON|ECHO);
22 : 0 : tcsetattr(fileno(stdin),0,&term);
23 : : }
24 : :
25 : : // Primary database file path used for read and write operations
26 : 554 : (void)m_del(conf(db_primary_file_path));
27 : :
28 : : // Primary database file name used in diagnostics and derived path handling
29 : 554 : (void)m_del(conf(db_file_name));
30 : :
31 : : // Filesystem traversal roots supplied as positional arguments outside --compare
32 : 554 : (void)m_array_del(conf(roots));
33 : :
34 : : // Database file paths supplied as positional arguments in --compare mode
35 : 554 : (void)m_array_del(conf(db_file_paths));
36 : :
37 : : // Database file name list built by db_determine_name()
38 : 554 : free_string_array(&(config->db_file_names));
39 : :
40 : : // PCRE2 pattern strings supplied via --ignore
41 : 554 : free_string_array(&(config->ignore));
42 : :
43 : : // PCRE2 pattern strings supplied via --include
44 : 554 : free_string_array(&(config->include));
45 : :
46 : : // PCRE2 pattern strings supplied via --lock-checksum
47 : 554 : free_string_array(&(config->lock_checksum));
48 : :
49 : : // Pre-compiled PCRE2 patterns for --ignore
50 : 554 : free_compiled_array(&config->ignore_pcre_compiled);
51 : :
52 : : // Pre-compiled PCRE2 patterns for --include
53 : 554 : free_compiled_array(&config->include_pcre_compiled);
54 : :
55 : : // Pre-compiled PCRE2 patterns for --lock-checksum
56 : 554 : free_compiled_array(&config->lock_checksum_pcre_compiled);
57 : 554 : }
|