]> sigrok.org Git - libsigrok.git/commit - src/scpi/scpi_vxi.c
scpi_vxi: fix memory leak for SCPI response data in VXI support code
authorDaniel Anselmi <redacted>
Fri, 21 May 2021 12:30:17 +0000 (14:30 +0200)
committerGerhard Sittig <redacted>
Mon, 7 Jun 2021 05:44:18 +0000 (07:44 +0200)
commited787682255cdecbb3ba8cefc87c20182b97ce7b
tree8cb709b303ea57744dc4aec3e4fed114b3aa0a42
parent7414fb55cb1ff4472176318d0e1146abfd2b7163
scpi_vxi: fix memory leak for SCPI response data in VXI support code

Routine scpi_vxi_read_data() invokes device_read_1(), which provides a
static buffer where dynamically allocated memory for SCPI response data
is kept. Release this memory after getting a copy of the response data,
before the next device_read_1() call loses the reference.

Valgrind stats without the fix:

  ==238825== LEAK SUMMARY:
  ==238825== definitely lost: 45,547,737 bytes in 18,331 blocks
  ==238825== indirectly lost: 0 bytes in 0 blocks
  ==238825== possibly lost: 48,154 bytes in 14 blocks
  ==238825== still reachable: 42,859 bytes in 288 blocks
  ==238825== suppressed: 0 bytes in 0 blocks

Valgrind stats with the fix:

  ==239413== LEAK SUMMARY:
  ==239413== definitely lost: 40 bytes in 2 blocks
  ==239413== indirectly lost: 0 bytes in 0 blocks
  ==239413== possibly lost: 0 bytes in 0 blocks
  ==239413== still reachable: 38,613 bytes in 287 blocks
  ==239413== suppressed: 0 bytes in 0 blocks

Remaining leaks in scpi_vxi_open() are of lesser severity because they
don't accumulate during execution.

[ gsi: rebase to recent master, reword commit message ]
src/scpi/scpi_vxi.c