Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests failing when run via valgrind(1) #6

Open
stephenmathieson opened this issue Feb 25, 2015 · 10 comments
Open

tests failing when run via valgrind(1) #6

stephenmathieson opened this issue Feb 25, 2015 · 10 comments
Assignees
Labels

Comments

@stephenmathieson
Copy link
Contributor

stephenmathieson at UTA in ~/repos/github.com/littlstar/b64.c on master
$ valgrind ./test
==1936== Memcheck, a memory error detector
==1936== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al.
==1936== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info
==1936== Command: ./test
==1936== 
==1936== Invalid write of size 1
==1936==    at 0x400E13: b64_encode (in ~/repos/github.com/littlstar/b64.c/test)
==1936==    by 0x400815: main (in ~/repos/github.com/littlstar/b64.c/test)
==1936==  Address 0x51f1128 is 0 bytes after a block of size 8 alloc'd
==1936==    at 0x4C2B7B2: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==1936==    by 0x400DED: b64_encode (in ~/repos/github.com/littlstar/b64.c/test)
==1936==    by 0x400815: main (in ~/repos/github.com/littlstar/b64.c/test)
==1936== 
==1936== Invalid write of size 1
==1936==    at 0x400E4D: b64_encode (in ~/repos/github.com/littlstar/b64.c/test)
==1936==    by 0x400815: main (in ~/repos/github.com/littlstar/b64.c/test)
==1936==  Address 0x51f11ca is 0 bytes after a block of size 10 alloc'd
==1936==    at 0x4C2B7B2: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==1936==    by 0x400E3D: b64_encode (in ~/repos/github.com/littlstar/b64.c/test)
==1936==    by 0x400815: main (in ~/repos/github.com/littlstar/b64.c/test)
==1936== 
==1936== Conditional jump or move depends on uninitialised value(s)
==1936==    at 0x400826: main (in ~/repos/github.com/littlstar/b64.c/test)
==1936== 
==1936== Conditional jump or move depends on uninitialised value(s)
==1936==    at 0x400839: main (in ~/repos/github.com/littlstar/b64.c/test)
==1936== 
test: test.c:28: main: Assertion `0 == strcmp("YnJhZGxleQ==", (char *) b64_encode((const unsigned char *) "bradley", strlen((char *) (const unsigned char *) "bradley")))' failed.
==1936== 
==1936== HEAP SUMMARY:
==1936==     in use at exit: 13 bytes in 1 blocks
==1936==   total heap usage: 11 allocs, 10 frees, 643 bytes allocated
==1936== 
==1936== LEAK SUMMARY:
==1936==    definitely lost: 13 bytes in 1 blocks
==1936==    indirectly lost: 0 bytes in 0 blocks
==1936==      possibly lost: 0 bytes in 0 blocks
==1936==    still reachable: 0 bytes in 0 blocks
==1936==         suppressed: 0 bytes in 0 blocks
==1936== Rerun with --leak-check=full to see details of leaked memory
==1936== 
==1936== For counts of detected and suppressed errors, rerun with: -v
==1936== Use --track-origins=yes to see where uninitialised values come from
==1936== ERROR SUMMARY: 6 errors from 4 contexts (suppressed: 2 from 2)
Aborted
stephenmathieson at UTA in ~/repos/github.com/littlstar/b64.c on master
$ 
@jwerle
Copy link
Owner

jwerle commented Feb 25, 2015

wtf

@stephenmathieson
Copy link
Contributor Author

yeah, not only that, but it looks like the realloc()s are bad :/

@jwerle
Copy link
Owner

jwerle commented Feb 25, 2015

yeah.. this needs to be refactored
this is bad

this would probably solve it:

tmp = (char *) realloc(enc, size + 4);
if (NULL != tmp) {
  enc = tmp;
}

@stephenmathieson
Copy link
Contributor Author

lemme check

@stephenmathieson
Copy link
Contributor Author

nope, still broken:

$ valgrind --leak-check=full ./test
==2060== Memcheck, a memory error detector
==2060== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al.
==2060== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info
==2060== Command: ./test
==2060== 
==2060== Invalid write of size 1
==2060==    at 0x400A9E: b64_encode (in ~/repos/github.com/littlstar/b64.c/test)
==2060==    by 0x400847: main (in ~/repos/github.com/littlstar/b64.c/test)
==2060==  Address 0x51f1128 is 0 bytes after a block of size 8 alloc'd
==2060==    at 0x4C2B7B2: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==2060==    by 0x400A78: b64_encode (in ~/repos/github.com/littlstar/b64.c/test)
==2060==    by 0x400847: main (in ~/repos/github.com/littlstar/b64.c/test)
==2060== 
==2060== Invalid write of size 1
==2060==    at 0x400AD8: b64_encode (in ~/repos/github.com/littlstar/b64.c/test)
==2060==    by 0x400847: main (in ~/repos/github.com/littlstar/b64.c/test)
==2060==  Address 0x51f11ca is 0 bytes after a block of size 10 alloc'd
==2060==    at 0x4C2B7B2: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==2060==    by 0x400AC8: b64_encode (in ~/repos/github.com/littlstar/b64.c/test)
==2060==    by 0x400847: main (in ~/repos/github.com/littlstar/b64.c/test)
==2060== 
==2060== Conditional jump or move depends on uninitialised value(s)
==2060==    at 0x4C2CBF4: __GI_strcmp (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==2060==    by 0x40085E: main (in ~/repos/github.com/littlstar/b64.c/test)
==2060== 
==2060== Conditional jump or move depends on uninitialised value(s)
==2060==    at 0x400861: main (in ~/repos/github.com/littlstar/b64.c/test)
==2060== 
[...]

@jwerle
Copy link
Owner

jwerle commented Feb 25, 2015

hmm...!
did you fix all `realloc() calls ?

@brendanashworth
Copy link

also getting this issue on OS X so +1

@stephenmathieson
Copy link
Contributor Author

we should probably refactor to not rely on realloc and just compute the length of the encoded/decoded arrays beforehand so we just malloc once.

if a refactor is cool with you, i'll try to get something put together once i get some time together

@jwerle
Copy link
Owner

jwerle commented Mar 1, 2015

@stephenmathieson yeah absolutely

@denji
Copy link

denji commented Aug 18, 2015

Here found some leaks b64.c (c58610f)

[encode.c:41]: (error) Common realloc mistake: 'enc' nulled but not freed upon failure
[encode.c:66]: (error) Common realloc mistake: 'enc' nulled but not freed upon failure
[encode.c:73]: (error) Common realloc mistake: 'enc' nulled but not freed upon failure
[encode.c:79]: (error) Common realloc mistake: 'enc' nulled but not freed upon failure
[decode.c:61]: (error) Common realloc mistake: 'dec' nulled but not freed upon failure
[decode.c:95]: (error) Common realloc mistake: 'dec' nulled but not freed upon failure
[decode.c:102]: (error) Common realloc mistake: 'dec' nulled but not freed upon failure

@jwerle jwerle self-assigned this Aug 10, 2020
@jwerle jwerle added the bug label Aug 10, 2020
Repository owner deleted a comment from Azerxim Feb 6, 2024
Repository owner deleted a comment from skodumur Feb 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants