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 and
7 : : * restores console QuickEdit if it was disabled, then releases every
8 : : * dynamically managed configuration field. Libmem descriptors
9 : : * are deleted through the matching `m_del()` or `m_array_del()` helpers, while
10 : : * plain pointer arrays and compiled PCRE2 arrays use their own free helpers
11 : : */
12 : 1249 : void free_config(void)
13 : : {
14 : : /* This function was reviewed line by line by a human and is not AI-generated
15 : : Any change to this function requires separate explicit approval */
16 : :
17 : : // Restore terminal echo and canonical mode only when stdin is a real terminal
18 [ - + ]: 1249 : if(isatty(fileno(stdin)))
19 : : {
20 : : struct termios term;
21 : 0 : tcgetattr(fileno(stdin),&term);
22 : 0 : term.c_lflag |= (ICANON|ECHO);
23 : 0 : tcsetattr(fileno(stdin),0,&term);
24 : : }
25 : :
26 : : #ifdef __MSYS__
27 : : // Restore the original QuickEdit setting for mouse selection in the Windows console
28 : : restore_console_quick_edit();
29 : : #endif
30 : :
31 : : // Clear the borrowed configuration path
32 : 1249 : config->config_file_path = NULL;
33 : :
34 : : // Clear the configuration line used for option error reporting
35 : 1249 : config->config_file_error_line = -1;
36 : :
37 : : // Primary database file path used for read and write operations
38 : 1249 : (void)m_del(conf(db_primary_file_path));
39 : :
40 : : // Primary database file name used in diagnostics and derived path handling
41 : 1249 : (void)m_del(conf(db_file_name));
42 : :
43 : : // Filesystem traversal roots supplied as positional arguments outside --compare
44 : 1249 : (void)m_array_del(conf(roots));
45 : :
46 : : // Database file paths supplied as positional arguments in --compare mode
47 : 1249 : (void)m_array_del(conf(db_file_paths));
48 : :
49 : : // Database file name list built by db_determine_name()
50 : 1249 : free_string_array(&(config->db_file_names));
51 : :
52 : : // PCRE2 pattern strings supplied via --ignore
53 : 1249 : free_string_array(&(config->ignore));
54 : :
55 : : // PCRE2 pattern strings supplied via --include
56 : 1249 : free_string_array(&(config->include));
57 : :
58 : : // PCRE2 pattern strings supplied via --lock-checksum
59 : 1249 : free_string_array(&(config->lock_checksum));
60 : :
61 : : // Pre-compiled PCRE2 patterns for --ignore
62 : 1249 : free_compiled_array(&config->ignore_pcre_compiled);
63 : :
64 : : // Pre-compiled PCRE2 patterns for --include
65 : 1249 : free_compiled_array(&config->include_pcre_compiled);
66 : :
67 : : // Pre-compiled PCRE2 patterns for --lock-checksum
68 : 1249 : free_compiled_array(&config->lock_checksum_pcre_compiled);
69 : 1249 : }
|