Quantcast

invalid free() from static destructor on exit()

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

invalid free() from static destructor on exit()

A. Lester Buck III
I am writing a text-to-speech loadable module for the open source
telephony server Freeswitch, using the new AWS Polly text-to-speech
service.  The AWS C++ SDK is C++11, templatized, etc., and I am wrapping
it in C with calls to factory methods returning opaque pointers to
objects.  I am not actually executing any AWS functions at the moment,
just the static allocation of these two variables that set up the SDK
and the client.

static Aws::SDKOptions options;
static Aws::Client::ClientConfiguration config;

The rest of my Freeswitch module code is stubbed out, and makes no AWS
calls.  When I start and stop Freeswitch, the stub Polly module loads
and unloads.  At server exit, I get a free() error.  After recompiling
everything with -O0, I get this single invalid output from valgrind:

==5892== Invalid free() / delete / delete[] / realloc()
==5892==    at 0x4C29E90: free (vg_replace_malloc.c:473)
==5892==    by 0xF467A9D: Aws::Allocator<char>::deallocate(char*, unsigned long) (AWSAllocator.h:74)
==5892==    by 0xF467778: std::basic_string<char, std::char_traits<char>, Aws::Allocator<char> >::_Rep::_M_destroy(Aws::Allocator<char> const&) (basic_string.tcc:449)
==5892==    by 0xF4674F3: std::basic_string<char, std::char_traits<char>, Aws::Allocator<char> >::_Rep::_M_dispose(Aws::Allocator<char> const&) (basic_string.h:249)
==5892==    by 0xF467386: std::basic_string<char, std::char_traits<char>, Aws::Allocator<char> >::~basic_string() (basic_string.h:547)
==5892==    by 0xF46706F: Aws::Client::ClientConfiguration::~ClientConfiguration() (ClientConfiguration.h:48)
==5892==    by 0x68B9B28: __run_exit_handlers (exit.c:82)
==5892==    by 0x68B9B74: exit (exit.c:104)
==5892==    by 0x68A3B4B: (below main) (libc-start.c:321)
==5892==  Address 0xf95f6a0 is in the BSS segment of /usr/local/lib/libaws-cpp-sdk-core.so
==5892==
==5892==

I got the glibc source for my Linux and the last line of libc-start.c is
line 321, the return statement from main().

There are a bunch of small allocation errors in the rest of Freeswitch,
but no more "Invalid free/delete/delete[]/realloc()" errors.  I also
wrote a minimal dlopen/dlsym/dlclose main program to exercise the
loadable module, and got no free() errors from the static destructor,
though the build systems are somewhat different from my toy main and the
entire Freeswitch server.

The AWS C++ SDK has a flexible memory allocation system, but I am not
using any of that and thus it defaults to the system built in
malloc/free/new/delete.

I don't understand the last line:

Address 0xf95f6a0 is in the BSS segment of /usr/local/lib/libaws-cpp-\
sdk-core.so

Is there anything unusual in the trace?  How do I use this to figure out
where/why the free() error is happening?

Thanks!

------------------------------------------------------------------------------
Announcing the Oxford Dictionaries API! The API offers world-renowned
dictionary content that is easy and intuitive to access. Sign up for an
account today to start using our lexical data to power your apps and
projects. Get started today and enter our developer competition.
http://sdm.link/oxford
_______________________________________________
Valgrind-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/valgrind-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: invalid free() from static destructor on exit()

Julian Seward-2
On 08/03/17 07:16, A. Lester Buck III wrote:
> I don't understand the last line:
>
> Address 0xf95f6a0 is in the BSS segment of /usr/local/lib/libaws-cpp-\
> sdk-core.so

What this means is, the address that has been passed to free -- that is,
0xf95f6a0 -- is zero-initialised data in libaws-cpp-sdk-core.so and so
has not been allocated on the heap.  It's (the address of) a global
variable in libaws-cpp-sdk-core.so, in other words.

> How do I use this to figure out where/why the free() error is happening?

You can poke around more with GDB by rerunning the program on V with
--vgdb-error=0 and following the directions it gives.  GDB will stop at
the error (at all errors) and you can examine the program state at your
leisure.

J


------------------------------------------------------------------------------
Announcing the Oxford Dictionaries API! The API offers world-renowned
dictionary content that is easy and intuitive to access. Sign up for an
account today to start using our lexical data to power your apps and
projects. Get started today and enter our developer competition.
http://sdm.link/oxford
_______________________________________________
Valgrind-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/valgrind-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: invalid free() from static destructor on exit()

iraisr
2017-03-08 11:56 GMT+01:00 Julian Seward <[hidden email]>:

> On 08/03/17 07:16, A. Lester Buck III wrote:
>> I don't understand the last line:
>>
>> Address 0xf95f6a0 is in the BSS segment of /usr/local/lib/libaws-cpp-\
>> sdk-core.so
>
> What this means is, the address that has been passed to free -- that is,
> 0xf95f6a0 -- is zero-initialised data in libaws-cpp-sdk-core.so and so
> has not been allocated on the heap.  It's (the address of) a global
> variable in libaws-cpp-sdk-core.so, in other words.
>
>> How do I use this to figure out where/why the free() error is happening?
>
> You can poke around more with GDB by rerunning the program on V with
> --vgdb-error=0 and following the directions it gives.  GDB will stop at
> the error (at all errors) and you can examine the program state at your
> leisure.

If this is your first time debugging a program under gdb,
you might want to read this manual section:
http://valgrind.org/docs/manual/manual-core-adv.html#manual-core-adv.gdbserver

I.

------------------------------------------------------------------------------
Announcing the Oxford Dictionaries API! The API offers world-renowned
dictionary content that is easy and intuitive to access. Sign up for an
account today to start using our lexical data to power your apps and
projects. Get started today and enter our developer competition.
http://sdm.link/oxford
_______________________________________________
Valgrind-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/valgrind-users
Loading...