How to catch the c/c++ malloc error? - c++

I have a Java app which run a c++ application which calls my odbc driver and sometimes I receive the error ilke
myapp(601,0x7000017a5000) malloc: *** error for object 0x7fc645161a10: incorrect checksum for freed object - object was probably modified after being freed.
*** set a breakpoint in malloc_error_break to debug
I cannot use gdb or lldb because it occurs inside of mydriver.so module.
Is it possible to catch this error in the code?
Or somehow redefine the malloc_error_break and trap the error inside it?
How to detect what is the object ?
Is this an error of application which calls odbc or in my odbc code?

Related

How to debug C++ python extension?

I want to debug my C++ python extension library. Currently the library is throwing an exception and to figure out where, I want to use gdb. The problem is that gdb is not catching the exception stack. I did as following:
$ gdb python3
(gdb) run script.py
UserWarning: An exception occurred: sort_index(): detected NaN
And when I try to use backtrace:
(gdb) backtrace
No stack.
I know that such backtrace is possible because I already did that before, probably I am missing something. The library is being compiled with debug mode.
A Python exception will not cause GDB to stop—it knows only to stop on signals, not “normal”, private error handling. It might be possible to set a breakpoint on the Python functions that set the Python error indicator, but they might be inlined (or be macros).
Conveniently, you can set a “breakpoint” on the magic function that throws C++ exceptions—it’s called a catchpoint and is set with the odd-looking catch throw. (This will be very noisy if (caught) exceptions are more common than they ought to be in your code!)
Finally, note that you can’t ever let a C++ exception escape into Python—even to catch it in yet a larger C++ context, because Python doesn’t know how to clean up in that circumstance.

Invalid Pointer Xcode 8

I am developing an application in Xcode 8.1. It is used to find printers inside the network. It uses cpp files also for printer searching. But i got one error
malloc: *** error for object 0x6080000099f0: Invalid pointer dequeued from free list
*** set a breakpoint in malloc_error_break to debug
I enabled zombie to catch this exception but fails.Also i added malloc error break but fails. Added try catch but it shows error break inside try block. Please help me how to catch this exception and if someone already face this issue please help me how to solve this.

How to “set a breakpoint in malloc_error_break to debug” in Qt Creator?

My Qt5 app crashes when I hit the close window returning:
MyApp(28741,0x7fff7aa73000) malloc: *** error for object 0x7fc40bc8e300: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
The program has unexpectedly finished.
How to “set a breakpoint in malloc_error_break to debug” in Qt Creator 4 (Mac OS)?
Should be better to do it via terminal in lldb/gdb, how?
Reference: How to find reason for app crash on close?
In Breakpoints window, right click->Add Breakpoint... change Breakpoint type to Function name and type malloc_error_break in Funcion:. Another way is to open Debugger Console (Cmd+5) and type b malloc_error_break.

The eclipse synchronized C/C++ project fails to synchronize

I tried to create synchronized C/C++ project for linux kernel (very big project) with Eclipse kepler, however project synchronization always fails to start between local and remote host (initial files on local host).
I've got the following exception:
An internal error occurred during: "Remote Synchronization". Exception
caught during execution of add command.
However there is no issue if I create synchronized project for small project.
Does any one has an idea what cause this issue?
exception stack trace:
!ENTRY org.eclipse.core.jobs 4 2 2013-12-27 11:12:07.376
!MESSAGE An internal error occurred during: "Remote Synchronization".
!STACK 0
org.eclipse.jgit.api.errors.JGitInternalException: Exception caught during execution of add command
at org.eclipse.jgit.api.AddCommand.call(AddCommand.java:208)
at org.eclipse.ptp.internal.rdt.sync.git.core.GitRemoteSyncConnection.doCommit(GitRemoteSyncConnection.java:577)
at org.eclipse.ptp.internal.rdt.sync.git.core.GitRemoteSyncConnection.buildRepo(GitRemoteSyncConnection.java:242)
at org.eclipse.ptp.internal.rdt.sync.git.core.GitRemoteSyncConnection.<init>(GitRemoteSyncConnection.java:167)
at org.eclipse.ptp.internal.rdt.sync.git.core.GitSyncService.getSyncConnection(GitSyncService.java:211)
at org.eclipse.ptp.internal.rdt.sync.git.core.GitSyncService.getMergeConflictFiles(GitSyncService.java:174)
at org.eclipse.ptp.internal.rdt.sync.git.core.GitSyncService.synchronize(GitSyncService.java:399)
at org.eclipse.ptp.internal.rdt.sync.core.SyncRunner.synchronize(SyncRunner.java:38)
at org.eclipse.ptp.rdt.sync.core.SyncManager$SynchronizeJob.run(SyncManager.java:79)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53)
Caused by: org.eclipse.jgit.errors.LockFailedException: Cannot lock /home/oussama/devel/mylinux/.ptp-sync/index
at org.eclipse.jgit.dircache.DirCache.lock(DirCache.java:224)
at org.eclipse.jgit.dircache.DirCache.lock(DirCache.java:301)
at org.eclipse.jgit.dircache.DirCache.lock(DirCache.java:267)
at org.eclipse.jgit.lib.Repository.lockDirCache(Repository.java:1049)
at org.eclipse.jgit.api.AddCommand.call(AddCommand.java:138)
... 9 more
Judging from your stack trace it appears that EGit is choking on an orphaned lock file:
Cannot lock /home/oussama/devel/mylinux/.ptp-sync/index
Look for /home/oussama/devel/mylinus/.ptp-sync/index.lock. If it exists, delete it and try synchronizing again. See also, this Eclipse bug.

gdb: malloc(): memory corruption (fast):

When executing gdb> core-file , gdb gives the following errors and then crashes creating a core file:
Reading symbols from ./libtcmalloc_minimal.so.0...
*** glibc detected *** gdb: malloc(): memory corruption (fast): 0x0000000000ec04a0 ***
I haven't found any reference to gdb crashing with this error. Has anyone run into this? If so what can be done about it.
The version of GDB is: GNU gdb (GDB) SUSE (6.8.50.20090302-1.5.18)
Thanks
what can be done about it
Any crash in GDB itself is a bug.
However, nobody would care about this bug, unless it can be reproduced with current GDB (yours is 5 years old).
So, download current release of GDB (7.5.1 currently), and build it.
If it works, use it to debug your problem.
If it doesn't work, file a bug in GDB bugzilla.
If you get this error as a result of calling
ptr = (ptr_t*)malloc(sizeof(ptr_t));
in your program, it may be due a missing stdlib.h header.