From 787676e60a60f9067123580ffb079c2c36c157ff Mon Sep 17 00:00:00 2001 From: "Martin R. Smith" Date: Mon, 6 Jul 2020 14:12:49 +0100 Subject: [PATCH] Avoid potential memory leak If `spi` references the first element of sibling_pairs, then the decrement will bring `spi` out of the range of `sibling_pairs`, which triggers a memory warning in ASAN. As `spi` is not used before the `break;` statement, it's not clear that it is necessary to decrement its value at all; I wonder whether the line can be deleted entirely? My C++ knowledge is pretty thin, so it's quite possible that I'm overlooking something obvious here. --- tbr.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tbr.h b/tbr.h index b730e51..f65e693 100644 --- a/tbr.h +++ b/tbr.h @@ -2957,7 +2957,7 @@ void leaf_reduction_hlpr(utree &T1, utree &T2, nodemapping &twins, map // add to nodemapping twins.add(T1_new_terminal->get_label(), T2_new_terminal->get_label()); - spi--; + if (spi != sibling_pairs.begin()) spi--; sibling_pairs.erase(T1_a->get_label()); sibling_pairs.erase(T1_c->get_label()); break;