[PATCH] Fix resource leak found by Coverity
Gary Benson
gbenson@redhat.com
Wed Oct 10 13:53:00 GMT 2018
Hi all,
This commit fixes a resource leak found by Coverity where
find_oload_champ leaked every badness vector it calculated
bar the one it returned.
Built and regtested on RHEL 7.5 x86_64.
Ok to commit?
Thanks,
Gary
--
gdb/ChangeLog:
* valops.c (find_oload_champ): Fix resource leak found by
Coverity.
---
gdb/ChangeLog | 5 +++++
gdb/valops.c | 9 ++++++---
2 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/gdb/valops.c b/gdb/valops.c
index c45caef..db2d3ed 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -3024,8 +3024,6 @@ find_oload_champ (struct value **args, int nargs,
struct badness_vector **oload_champ_bv)
{
int ix;
- /* A measure of how good an overloaded instance is. */
- struct badness_vector *bv;
/* Index of best overloaded function. */
int oload_champ = -1;
/* Current ambiguity state for overload resolution. */
@@ -3075,13 +3073,15 @@ find_oload_champ (struct value **args, int nargs,
/* Compare parameter types to supplied argument types. Skip
THIS for static methods. */
- bv = rank_function (parm_types, nparms,
+ struct badness_vector *bv
+ = rank_function (parm_types, nparms,
args + static_offset,
nargs - static_offset);
if (!*oload_champ_bv)
{
*oload_champ_bv = bv;
+ bv = NULL;
oload_champ = 0;
}
else /* See whether current candidate is better or worse than
@@ -3095,7 +3095,9 @@ find_oload_champ (struct value **args, int nargs,
oload_ambiguous = 2;
break;
case 2: /* New champion, record details. */
+ xfree (*oload_champ_bv);
*oload_champ_bv = bv;
+ bv = NULL;
oload_ambiguous = 0;
oload_champ = ix;
break;
@@ -3103,6 +3105,7 @@ find_oload_champ (struct value **args, int nargs,
default:
break;
}
+ xfree (bv);
xfree (parm_types);
if (overload_debug)
{
--
1.8.3.1
More information about the Gdb-patches
mailing list