This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[committed] optinfo-emit-json.cc: fix trivial memory leak
- From: David Malcolm <dmalcolm at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Cc: David Malcolm <dmalcolm at redhat dot com>
- Date: Wed, 25 Jul 2018 11:07:28 -0400
- Subject: [committed] optinfo-emit-json.cc: fix trivial memory leak
There's a small leak in class optrecord_json_writer, which shows
up as a new leak in "make selftest-valgrind" as:
==50133== 40 bytes in 1 blocks are definitely lost in loss record 27 of 672
==50133== at 0x4A0645D: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==50133== by 0x1EF5CAF: xrealloc (xmalloc.c:177)
==50133== by 0xEDDA56: void va_heap::reserve<json::array*>(vec<json::array*, va_heap, vl_embed>*&, unsigned int, bool) (vec.h:288)
==50133== by 0xEDD74D: vec<json::array*, va_heap, vl_ptr>::reserve(unsigned int, bool) (vec.h:1621)
==50133== by 0xEDD515: vec<json::array*, va_heap, vl_ptr>::safe_push(json::array* const&) (vec.h:1730)
==50133== by 0xEDB060: optrecord_json_writer::optrecord_json_writer() (optinfo-emit-json.cc:124)
==50133== by 0xEDD141: selftest::test_building_json_from_dump_calls() (optinfo-emit-json.cc:935)
==50133== by 0xEDD3AF: selftest::optinfo_emit_json_cc_tests() (optinfo-emit-json.cc:955)
==50133== by 0x1DEB3AA: selftest::run_tests() (selftest-run-tests.c:78)
==50133== by 0x1065264: toplev::run_self_tests() (toplev.c:2225)
==50133== by 0x1065486: toplev::main(int, char**) (toplev.c:2303)
==50133== by 0x1E4A092: main (main.c:39)
The fix is trivial.
Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu;
manually checked "make selftest-valgrind" (which with this fix is now
back from four leaks down to three).
Committed to trunk as r262967 (under the "obvious" rule).
gcc/ChangeLog:
* optinfo-emit-json.cc (class optrecord_json_writer): Convert
field "m_scopes" from vec to auto_vec.
---
gcc/optinfo-emit-json.cc | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/gcc/optinfo-emit-json.cc b/gcc/optinfo-emit-json.cc
index 6460a81..2199d52 100644
--- a/gcc/optinfo-emit-json.cc
+++ b/gcc/optinfo-emit-json.cc
@@ -75,7 +75,7 @@ private:
json::array *m_root_tuple;
/* The currently open scopes, for expressing nested optimization records. */
- vec<json::array *> m_scopes;
+ auto_vec<json::array *> m_scopes;
};
/* optrecord_json_writer's ctor. Populate the top-level parts of the
--
1.8.5.3