From 337831e094afa48c1224e8bd0a5f70f1222b760a Mon Sep 17 00:00:00 2001 From: Bernd Busse Date: Thu, 22 Oct 2020 15:44:10 +0200 Subject: [PATCH] Fix memory errors reported by `scan-build`. - Fix non-critical memory-leak in `picom.c` and `options.c` where we don't free all allocated memory before dieing. - Explicitly allocate new branch in `c2.c` to silence false-positive memory-leak. --- src/c2.c | 3 ++- src/options.c | 30 +++++++++++++++++++++--------- src/picom.c | 1 + 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/c2.c b/src/c2.c index e3949c92..53b85c11 100644 --- a/src/c2.c +++ b/src/c2.c @@ -265,7 +265,8 @@ static inline void c2_ptr_reset(c2_ptr_t *pp) { * Combine two condition trees. */ static inline c2_ptr_t c2h_comb_tree(c2_b_op_t op, c2_ptr_t p1, c2_ptr_t p2) { - c2_ptr_t p = {.isbranch = true, .b = cmalloc(c2_b_t)}; + c2_ptr_t p = {.isbranch = true, .b = NULL}; + p.b = cmalloc(c2_b_t); p.b->neg = false; p.b->op = op; diff --git a/src/options.c b/src/options.c index 54ef937c..976b0a0f 100644 --- a/src/options.c +++ b/src/options.c @@ -521,6 +521,7 @@ bool get_cfg(options_t *opt, int argc, char *const *argv, bool shadow_enable, // Parse commandline arguments. Range checking will be done later. + bool failed = false; const char *deprecation_message attr_unused = "has been removed. If you encounter problems " "without this feature, please feel free to " @@ -567,11 +568,11 @@ bool get_cfg(options_t *opt, int argc, char *const *argv, bool shadow_enable, case 'C': log_error("Option `--no-dock-shadow`/`-C` has been removed. Please" " use the wintype option `shadow` of `dock` instead."); - return false; + failed = true; break; case 'G': log_error("Option `--no-dnd-shadow`/`-G` has been removed. Please " "use the wintype option `shadow` of `dnd` instead."); - return false; + failed = true; break; case 'm':; double tmp; tmp = normalize_d(atof(optarg)); @@ -604,7 +605,7 @@ bool get_cfg(options_t *opt, int argc, char *const *argv, bool shadow_enable, case 'a': case 's': log_error("-n, -a, and -s have been removed."); - return false; + failed = true; break; // Long options case 256: // --config @@ -659,13 +660,15 @@ bool get_cfg(options_t *opt, int argc, char *const *argv, bool shadow_enable, case 271: // --alpha-step log_error("--alpha-step has been removed, we now tries to " - "make use of all alpha values"); - return false; - case 272: log_error("use of --dbe is deprecated"); return false; + "make use of all alpha values"); + failed = true; break; + case 272: + log_error("--dbe has been removed"); + failed = true; break; case 273: log_error("--paint-on-overlay has been removed, the feature is enabled " - "whenever possible"); - return false; + "whenever possible"); + failed = true; break; P_CASEBOOL(274, sw_opti); case 275: // --vsync-aggressive @@ -805,7 +808,7 @@ bool get_cfg(options_t *opt, int argc, char *const *argv, bool shadow_enable, case 312: // --xrender-sync log_error("Please use --xrender-sync-fence instead of --xrender-sync"); - return false; + failed = true; break; P_CASEBOOL(313, xrender_sync_fence); P_CASEBOOL(315, no_fading_destroyed_argb); P_CASEBOOL(316, force_win_blend); @@ -866,12 +869,21 @@ bool get_cfg(options_t *opt, int argc, char *const *argv, bool shadow_enable, #undef P_CASEBOOL } // clang-format on + + if (failed) { + // Parsing this option has failed, break the loop + break; + } } // Restore LC_NUMERIC setlocale(LC_NUMERIC, lc_numeric_old); free(lc_numeric_old); + if (failed) { + return false; + } + if (opt->monitor_repaint && opt->backend != BKEND_XRENDER && !opt->experimental_backends) { log_warn("--monitor-repaint has no effect when backend is not xrender"); diff --git a/src/picom.c b/src/picom.c index 83ac42d4..65b39a80 100644 --- a/src/picom.c +++ b/src/picom.c @@ -2515,6 +2515,7 @@ int main(int argc, char **argv) { if (pid_file) { log_trace("remove pid file %s", pid_file); unlink(pid_file); + free(pid_file); } log_deinit_tls();