cap_disas_plugin leaks memory

Bug #1860610 reported by Robert Henry
10
This bug affects 1 person
Affects Status Importance Assigned to Milestone
QEMU
Expired
Undecided
Unassigned

Bug Description

Looking at origin/master head, the function cap_disas_plugin leaks memory.

per capstone's examples using their ABI, cs_free(insn, count); needs to called just before cs_close.

I discovered this running qemu under valgrind.

Tags: plugin tcg
Revision history for this message
Alex Bennée (ajbennee) wrote :

It looks like this will fail on all the other capstone cases as well. Is this an API change across versions?

tags: added: plugin tcg
Changed in qemu:
assignee: nobody → Alex Bennée (ajbennee)
Revision history for this message
Robert Henry (mhodog) wrote :

I run git blame in the capstone repository, and cs_free has been around for at least 4 years in the capstone ABI. I can not tell if the need to call cs_free is a (new) requirement. Documentation capstone is a little informal...

Revision history for this message
Alex Bennée (ajbennee) wrote :

What command line where you using? I've been unable to replicate the valgrind warning with a riscv64-linux-user run of hello with the libhowvec.so plugin. Valgrind does complain about a bunch of other stuff though.

Revision history for this message
Alex Bennée (ajbennee) wrote :

Looking at the way disas is structured it seems cap_insn is allocated once (per thread) and re-used for each disassembly so we shouldn't be free'ing it after each usage. In fact the comments to cap_disas_start imply we want to do better than re-initialising the library for every set of instructions we disassemble.

It is true that we don't clean-up any of the disassembly machinery on exit but the same can be said for a lot of QEMU's static state. So currently I don't see a leak rather than a one-time allocation. Unless I can reproduce the leak I'm going to mark this as incomplete for now.

Changed in qemu:
status: New → Incomplete
Thomas Huth (th-huth)
Changed in qemu:
assignee: Alex Bennée (ajbennee) → nobody
Revision history for this message
Launchpad Janitor (janitor) wrote :

[Expired for QEMU because there has been no activity for 60 days.]

Changed in qemu:
status: Incomplete → Expired
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.