Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #32290
| References | <e5ab59f8-da39-4d50-bca2-63a5f5ec0cc2@googlegroups.com> <mailman.2940.1351349811.27098.python-list@python.org> <65b67e08-e06e-4a6a-8bd5-eb6f0f74630f@googlegroups.com> |
|---|---|
| Date | 2012-10-28 07:26 +1100 |
| Subject | Re: ctypes free memory which is allocated in C DLL |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2945.1351369606.27098.python-list@python.org> (permalink) |
On Sun, Oct 28, 2012 at 2:40 AM, Ken Chen <zlchen.ken@gmail.com> wrote: > Yes, I agree writing a corresponding API to free the memory is the best practice and best bet. > Sometimes, the third party API may not provide that. Then that's a majorly dangerous third party API. The only time it's safe to provide a half-only API like that is when the code gets statically linked with the application, so there's a guarantee that malloc() in one place corresponds to free() in another. > After digging the Python manual again and again. > I finally figure out why windll.msvcrt.free is failing. > > As the manual stated below, the DLL is using another version of msvcrt lib which is different than the builtin windll.msvcrt. After I explicitly load the msvcrt which built the DLL, things are getting function now. That's still vulnerable. There's really no guarantee about _anything_ with mismatched memory allocators; it's theoretically possible for compiler switches to change the behaviour of malloc/free such that compiling malloc in debug mode and free in release mode would crash your program. (I don't know off-hand of any compilers/libraries that do that specifically, but there are similar changes done in other ways.) If a DLL allocates memory and doesn't deallocate it, lean on its author to complete the job. ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
ctypes free memory which is allocated in C DLL zlchen.ken@gmail.com - 2012-10-27 07:42 -0700
Re: ctypes free memory which is allocated in C DLL Chris Angelico <rosuav@gmail.com> - 2012-10-28 01:56 +1100
Re: ctypes free memory which is allocated in C DLL Ken Chen <zlchen.ken@gmail.com> - 2012-10-27 08:40 -0700
Re: ctypes free memory which is allocated in C DLL Chris Angelico <rosuav@gmail.com> - 2012-10-28 07:26 +1100
Re: ctypes free memory which is allocated in C DLL Ken Chen <zlchen.ken@gmail.com> - 2012-10-27 08:40 -0700
Re: ctypes free memory which is allocated in C DLL Nobody <nobody@nowhere.com> - 2012-10-27 23:26 +0100
Re: ctypes free memory which is allocated in C DLL zlchen.ken@gmail.com - 2012-10-27 19:05 -0700
csiph-web