[1/2] Avoid potential memory leak in Rust parser
Checks
| Context |
Check |
Description |
| linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 |
success
|
Build passed
|
| linaro-tcwg-bot/tcwg_gdb_build--master-arm |
success
|
Build passed
|
| linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 |
success
|
Test passed
|
| linaro-tcwg-bot/tcwg_gdb_check--master-arm |
success
|
Test passed
|
Commit Message
rust_parser::parse_field has some support for completion. This code
allocates a rust_structop using plain 'new', then stores it somewhere.
However, between the allocation and the store, the function calls
"lex()", which might throw. This would leak the rust_structop object.
This patch rearranges the code slightly to avoid the memory leak.
---
gdb/rust-parse.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
@@ -1544,17 +1544,18 @@ rust_parser::parse_field (operation_up &&lhs)
case COMPLETE:
{
bool is_complete = current_token == COMPLETE;
- auto struct_op = new rust_structop (std::move (lhs),
- std::string (current_string_val));
+ auto struct_op
+ = std::make_unique<rust_structop> (std::move (lhs),
+ std::string (current_string_val));
lex ();
if (is_complete)
{
- completion_op.reset (struct_op);
- pstate->mark_struct_expression (struct_op);
+ pstate->mark_struct_expression (struct_op.get ());
+ completion_op = std::move (struct_op);
/* Throw to the outermost level of the parser. */
error (_("not really an error"));
}
- result.reset (struct_op);
+ result = std::move (struct_op);
}
break;