base64.c
base64.c copied to clipboard
ERROR: LeakSanitizer: detected memory leaks in test.c
memory leak detected
==34135==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 9 byte(s) in 1 object(s) allocated from:
#0 0x7f97d8fb7867 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:145
https://github.com/elzoughby/Base64/pull/1 0x55c784089423 in test_b64_encodef /home/jason/Desktop/libbase64/test.c:169
https://github.com/elzoughby/Base64/issues/2 0x55c7840885d9 in main /home/jason/Desktop/libbase64/test.c:60
https://github.com/elzoughby/Base64/issues/3 0x7f97d8d04d8f in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58
SUMMARY: AddressSanitizer: 9 byte(s) leaked in 1 allocation(s)
the fix is to add a few calls to free
FILE *pFile;
pFile = fopen("B64_TEST01A.tmp","wb");
if (pFile==NULL)
return 0;
int i, j=0;
unsigned int test_a[] = HEXNUM_B;
unsigned int size_a = NELEMS(test_a);
for (i=0;i<size_a;i++) {
fputc(test_a[i],pFile);
}
fclose(pFile);
j = b64_encodef("B64_TEST01A.tmp","B64_TEST01B.tmp");
remove("B64_TEST01A.tmp");
if (!j)
return 0;
pFile = fopen("B64_TEST01B.tmp","rb");
if (pFile==NULL)
return 0;
char *out = malloc(j+1);
fgets(out,j+1,pFile);
fclose(pFile);
remove("B64_TEST01B.tmp");
printf("\tComparing \"%s\" to \"%s\" : ",STRING_B,out);
if (strcmp(STRING_B,out)==0)
{
free(out); //Add this line and the one below
return 1;
}
free(out); //add this line too
return 0;
}```
Great, thanks for this! I'll have a look soon enough.