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

Memory leaks in ScardEstablishContext() #55

Closed
KkVova opened this issue Jan 30, 2019 · 6 comments
Closed

Memory leaks in ScardEstablishContext() #55

KkVova opened this issue Jan 30, 2019 · 6 comments

Comments

@KkVova
Copy link

KkVova commented Jan 30, 2019

I use libpcsclite and recently faced with some memory leaks while running ScardEstablishContext() under Valgrind.

I came across this link and tried to find topic about it, but unsuccessfully.

I’ve made this sample to reproduce leaks.

g++ test_leaks.cpp -o test_leaks -ldl -I/usr/include/PCSC
//test_leaks.cpp
 
#include <dlfcn.h>
#include <cstddef>
#include <winscard.h>

int main()
{
     typedef LONG (*SCardEstablishContext_t)(DWORD, LPCVOID,LPCVOID,LPSCARDCONTEXT);
     typedef LONG (*SCardReleaseContext_t)(SCARDCONTEXT);

     void* module = dlopen("libpcsclite.so", RTLD_NOW);

     SCardEstablishContext_t SCardEstablishContext = (SCardEstablishContext_t)dlsym(module, "SCardEstablishContext");
     SCardReleaseContext_t SCardReleaseContext = (SCardReleaseContext_t)dlsym(module, "SCardReleaseContext");

     SCARDCONTEXT ctx;
     SCardEstablishContext(0, NULL, NULL, &ctx);
     SCardReleaseContext(ctx);

     dlclose(module);
     return 0;
}

Valgrind report

valgrind ./test_leaks
==9662== Memcheck, a memory error detector
==9662== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==9662== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==9662== Command: ./test_leaks
==9662== 
==9662== 
==9662== HEAP SUMMARY:
==9662==     in use at exit: 1,860 bytes in 9 blocks
==9662==   total heap usage: 19 allocs, 10 frees, 3,741 bytes allocated
==9662== 
==9662== LEAK SUMMARY:
==9662==    definitely lost: 40 bytes in 1 blocks
==9662==    indirectly lost: 72 bytes in 3 blocks
==9662==      possibly lost: 0 bytes in 0 blocks
==9662==    still reachable: 1,748 bytes in 5 blocks
==9662==         suppressed: 0 bytes in 0 blocks
==9662== Rerun with --leak-check=full to see details of leaked memory
==9662== 
==9662== For counts of detected and suppressed errors, rerun with: -v
==9662== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

Was it fixed or what can I do to imporve the situation?

Thanks for attention.

@LudovicRousseau
Copy link
Owner

I think this is this bug https://salsa.debian.org/rousseau/PCSC/issues/1
No, it is not yet fixed.

Do you plan to propose a fix?

@LudovicRousseau
Copy link
Owner

@ValZapod it is not hard to fix. But the issue is really minor.
Please propose a patch if you want.

@wagnst
Copy link

wagnst commented Dec 2, 2021

We have the same issue. Is there any update here? This seems not to be fixed.

@LudovicRousseau
Copy link
Owner

@wagnst do you use dlopen("libpcsclite.so", RTLD_NOW); in your code?

@LudovicRousseau
Copy link
Owner

Fixed in c94aeb5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants
@LudovicRousseau @wagnst @KkVova and others