OSDN Git Service

[libunwind] Fix memory leak in handling of DW_CFA_remember_state and DW_CFA_restore_state
authorJorge Gorbe Moya <jgorbe@google.com>
Tue, 18 Feb 2020 19:48:02 +0000 (11:48 -0800)
committerJorge Gorbe Moya <jgorbe@google.com>
Tue, 18 Feb 2020 19:57:18 +0000 (11:57 -0800)
commit1ae8d81147a0724cc972054afbd72943032e4832
tree1fc5e0bbdd4f8b6de252cd250b8bc00a53702248
parentb8bea9346af4f2644c9a1bd29710c5e3efbbd7d3
[libunwind] Fix memory leak in handling of DW_CFA_remember_state and DW_CFA_restore_state

parseInstructions() doesn't always process the whole set of DWARF
instructions for a frame. It will stop once the target PC is reached, or
if malformed instructions are found. So, for example, if we have an
instruction sequence like this:

```
<start>
...
DW_CFA_remember_state
...
DW_CFA_advance_loc past the location we're unwinding at (pcoffset in parseInstructions() main loop)
...
DW_CFA_restore_state
<end>
```

... the saved state will never be freed, even though the
DW_CFA_remember_state opcode has a matching DW_CFA_restore_state later
in the sequence.

This change adds code to free whatever is left on rememberStack after
parsing the CIE and the FDE instructions.

Differential Revision: https://reviews.llvm.org/D66904
libunwind/src/DwarfParser.hpp
libunwind/test/remember_state_leak.pass.sh.s [new file with mode: 0644]