mccdaq / daqhats

MCC DAQ HAT Library for Raspberry Pi
Other
128 stars 89 forks source link

Testing with Valgrind #4

Closed mattrust closed 5 years ago

mattrust commented 5 years ago

Hi,

when I run this simple example... `

include <daqhats/daqhats.h>

int main(void) { int error; error = mcc118_open(0); if (error == 0) { mcc118_close(0); } return 0; } ` ... under Valgrind I get some errors:

pi@raspberrypi:~ $ valgrind --tool=memcheck --track-origins=yes ./a.out ==1330== Memcheck, a memory error detector ==1330== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. ==1330== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info ==1330== Command: ./a.out ==1330== ==1330== Invalid read of size 1 ==1330== at 0x484B200: strlen (vg_replace_strmem.c:458) ==1330== by 0x489A72B: cJSON_ParseWithOpts (cJSON.c:1008) ==1330== by 0x48950EF: mcc118_open (mcc118.c:1142) ==1330== by 0x10637: main (in /home/pi/a.out) ==1330== Address 0x4b163fa is 0 bytes after a block of size 530 alloc'd ==1330== at 0x4847568: malloc (vg_replace_malloc.c:299) ==1330== by 0x489513F: mcc118_open (mcc118.c:1104) ==1330== by 0x10637: main (in /home/pi/a.out) ==1330== ==1330== Conditional jump or move depends on uninitialised value(s) ==1330== at 0x4894B5C: _spi_transfer (mcc118.c:508) ==1330== by 0x4894FF3: mcc118_open (mcc118.c:1172) ==1330== by 0x10637: main (in /home/pi/a.out) ==1330== Uninitialised value was created by a heap allocation ==1330== at 0x4847568: malloc (vg_replace_malloc.c:299) ==1330== by 0x4894983: _spi_transfer (mcc118.c:397) ==1330== by 0x4894FF3: mcc118_open (mcc118.c:1172) ==1330== by 0x10637: main (in /home/pi/a.out) ==1330== ==1330== Conditional jump or move depends on uninitialised value(s) ==1330== at 0x4894C70: _parse_buffer (mcc118.c:272) ==1330== by 0x4894C70: _spi_transfer (mcc118.c:544) ==1330== by 0x4894FF3: mcc118_open (mcc118.c:1172) ==1330== by 0x10637: main (in /home/pi/a.out) ==1330== Uninitialised value was created by a heap allocation ==1330== at 0x4847568: malloc (vg_replace_malloc.c:299) ==1330== by 0x4894983: _spi_transfer (mcc118.c:397) ==1330== by 0x4894FF3: mcc118_open (mcc118.c:1172) ==1330== by 0x10637: main (in /home/pi/a.out) ==1330== ==1330== Conditional jump or move depends on uninitialised value(s) ==1330== at 0x4894CF4: _parse_buffer (mcc118.c:292) ==1330== by 0x4894CF4: _spi_transfer (mcc118.c:544) ==1330== by 0x4894FF3: mcc118_open (mcc118.c:1172) ==1330== by 0x10637: main (in /home/pi/a.out) ==1330== Uninitialised value was created by a heap allocation ==1330== at 0x4847568: malloc (vg_replace_malloc.c:299) ==1330== by 0x4894983: _spi_transfer (mcc118.c:397) ==1330== by 0x4894FF3: mcc118_open (mcc118.c:1172) ==1330== by 0x10637: main (in /home/pi/a.out) ==1330== ==1330== Conditional jump or move depends on uninitialised value(s) ==1330== at 0x4894D1C: _parse_buffer (mcc118.c:307) ==1330== by 0x4894D1C: _spi_transfer (mcc118.c:544) ==1330== by 0x4894FF3: mcc118_open (mcc118.c:1172) ==1330== by 0x10637: main (in /home/pi/a.out) ==1330== Uninitialised value was created by a heap allocation ==1330== at 0x4847568: malloc (vg_replace_malloc.c:299) ==1330== by 0x4894983: _spi_transfer (mcc118.c:397) ==1330== by 0x4894FF3: mcc118_open (mcc118.c:1172) ==1330== by 0x10637: main (in /home/pi/a.out) ==1330== ==1330== Conditional jump or move depends on uninitialised value(s) ==1330== at 0x4894D34: _parse_buffer (mcc118.c:307) ==1330== by 0x4894D34: _spi_transfer (mcc118.c:544) ==1330== by 0x4894FF3: mcc118_open (mcc118.c:1172) ==1330== by 0x10637: main (in /home/pi/a.out) ==1330== Uninitialised value was created by a heap allocation ==1330== at 0x4847568: malloc (vg_replace_malloc.c:299) ==1330== by 0x4894983: _spi_transfer (mcc118.c:397) ==1330== by 0x4894FF3: mcc118_open (mcc118.c:1172) ==1330== by 0x10637: main (in /home/pi/a.out) ==1330== ==1330== Conditional jump or move depends on uninitialised value(s) ==1330== at 0x4894D64: _spi_transfer (mcc118.c:569) ==1330== by 0x4894FF3: mcc118_open (mcc118.c:1172) ==1330== by 0x10637: main (in /home/pi/a.out) ==1330== Uninitialised value was created by a heap allocation ==1330== at 0x4847568: malloc (vg_replace_malloc.c:299) ==1330== by 0x4894983: _spi_transfer (mcc118.c:397) ==1330== by 0x4894FF3: mcc118_open (mcc118.c:1172) ==1330== by 0x10637: main (in /home/pi/a.out) ==1330== ==1330== Conditional jump or move depends on uninitialised value(s) ==1330== at 0x4894DE0: _spi_transfer (mcc118.c:572) ==1330== by 0x4894FF3: mcc118_open (mcc118.c:1172) ==1330== by 0x10637: main (in /home/pi/a.out) ==1330== Uninitialised value was created by a heap allocation ==1330== at 0x4847568: malloc (vg_replace_malloc.c:299) ==1330== by 0x4894983: _spi_transfer (mcc118.c:397) ==1330== by 0x4894FF3: mcc118_open (mcc118.c:1172) ==1330== by 0x10637: main (in /home/pi/a.out) ==1330== ==1330== Use of uninitialised value of size 4 ==1330== at 0x4894DE0: _spi_transfer (mcc118.c:572) ==1330== by 0x4894FF3: mcc118_open (mcc118.c:1172) ==1330== by 0x10637: main (in /home/pi/a.out) ==1330== Uninitialised value was created by a heap allocation ==1330== at 0x4847568: malloc (vg_replace_malloc.c:299) ==1330== by 0x4894983: _spi_transfer (mcc118.c:397) ==1330== by 0x4894FF3: mcc118_open (mcc118.c:1172) ==1330== by 0x10637: main (in /home/pi/a.out) ==1330== ==1330== Conditional jump or move depends on uninitialised value(s) ==1330== at 0x4895020: mcc118_open (mcc118.c:1179) ==1330== by 0x10637: main (in /home/pi/a.out) ==1330== Uninitialised value was created by a heap allocation ==1330== at 0x4847568: malloc (vg_replace_malloc.c:299) ==1330== by 0x4894983: _spi_transfer (mcc118.c:397) ==1330== by 0x4894FF3: mcc118_open (mcc118.c:1172) ==1330== by 0x10637: main (in /home/pi/a.out) ==1330== ==1330== ==1330== HEAP SUMMARY: ==1330== in use at exit: 0 bytes in 0 blocks ==1330== total heap usage: 36 allocs, 36 frees, 6,135 bytes allocated ==1330== ==1330== All heap blocks were freed -- no leaks are possible ==1330== ==1330== For counts of detected and suppressed errors, rerun with: -v ==1330== ERROR SUMMARY: 15 errors from 10 contexts (suppressed: 6 from 3)

Would you please check?

nwright-mcc commented 5 years ago

I checked them, and these are not major issues. The first is due to a string read from the EEPROM not being null terminated, the remaining are because valgrind doesn't know the memory blocks are initialized by SPI reads. They will all be cleared in the next release.