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

AddressSanitizer: alloc-dealloc-mismatch in operator delete(void*, unsigned long) #5

Open
vakond opened this issue Jan 24, 2019 · 1 comment

Comments

@vakond
Copy link

vakond commented Jan 24, 2019

Address sanitizer (Linux, g++ version 6.3.0 20170516 (Debian 6.3.0-18+deb9u1)) reports an error:

=================================================================
==19515==ERROR: AddressSanitizer: alloc-dealloc-mismatch (operator new [] vs operator delete) on 0x6020001005b0
#0 in operator delete(void*, unsigned long) (/usr/lib/x86_64-linux-gnu/libasan.so.3+0xc37f0)
#1 in generic::Generic::deleteValue() project/api/Generic.cpp:678
#2 in carecord::CaRecord::~CaRecord() project/api/CaRecord.cpp:43
#3 in qcaobject::QCaObject::processData(void*) project/data/QCaObject.cpp:1261
#4 in qcaobject::QCaObject::processEvent(QCaEventUpdate*) project/data/QCaObject.cpp:829
#5 in QCaEventFilter::eventFilter(QObject*, QEvent*) project/data/QCaEventFilter.cpp:145
#6 in QCoreApplicationPrivate::sendThroughObjectEventFilters(QObject*, QEvent*) (/usr/lib/x86_64-linux-gnu/libQtCore.so.4+0x18b0a0)
#7 in QApplicationPrivate::notify_helper(QObject*, QEvent*) (/usr/lib/x86_64-linux-gnu/libQtGui.so.4+0x1c452b)
#8 in QApplication::notify(QObject*, QEvent*) (/usr/lib/x86_64-linux-gnu/libQtGui.so.4+0x1cb52b)
#9 in QCoreApplication::notifyInternal(QObject*, QEvent*) (/usr/lib/x86_64-linux-gnu/libQtCore.so.4+0x18af1c)
#10 in QCoreApplicationPrivate::sendPostedEvents(QObject*, int, QThreadData*) (/usr/lib/x86_64-linux-gnu/libQtCore.so.4+0x18ea15)
#11 (/usr/lib/x86_64-linux-gnu/libQtCore.so.4+0x1bb702)
#12 in g_main_context_dispatch (/lib/x86_64-linux-gnu/libglib-2.0.so.0+0x4a7f6)
#13 (/lib/x86_64-linux-gnu/libglib-2.0.so.0+0x4aa5f)
#14 in g_main_context_iteration (/lib/x86_64-linux-gnu/libglib-2.0.so.0+0x4ab0b)
#15 in QEventDispatcherGlib::processEvents(QFlagsQEventLoop::ProcessEventsFlag) (/usr/lib/x86_64-linux-gnu/libQtCore.so.4+0x1bb853)
#16 in QEventLoop::processEvents(QFlagsQEventLoop::ProcessEventsFlag) (/usr/lib/x86_64-linux-gnu/libQtCore.so.4+0x1897ee)
#17 in QEventLoop::exec(QFlagsQEventLoop::ProcessEventsFlag) (/usr/lib/x86_64-linux-gnu/libQtCore.so.4+0x189b54)
#18 in QThread::exec() (/usr/lib/x86_64-linux-gnu/libQtCore.so.4+0x784d8)
#19 (/usr/lib/x86_64-linux-gnu/libQtCore.so.4+0x7ada9)
#20 in start_thread (/lib/x86_64-linux-gnu/libpthread.so.0+0x75a9)
#21 in __clone (/lib/x86_64-linux-gnu/libc.so.6+0xf6cbe)

0x6020001005b0 is located 0 bytes inside of 4-byte region [0x6020001005b0,0x6020001005b4)
allocated by thread T7 (CAC-TCP-recv) here:
#0 0x7fde9ed95d70 in operator new[](unsigned long) (/usr/lib/x86_64-linux-gnu/libasan.so.3+0xc2d70)
#1 0x7fde9d7079d6 in generic::Generic::setLong(int*, unsigned long) project/api/Generic.cpp:317

Thread T3 (QThread) created by T0 here:
#0 0x7fde9ed03f59 in __interceptor_pthread_create (/usr/lib/x86_64-linux-gnu/libasan.so.3+0x30f59)
#1 0x7fde9b49c3a9 in QThread::start(QThread::Priority) (/usr/lib/x86_64-linux-gnu/libQtCore.so.4+0x7a3a9)

Thread T7 (CAC-TCP-recv) created by T6 (CAC-UDP) here:
#0 0x7fde9ed03f59 in __interceptor_pthread_create (/usr/lib/x86_64-linux-gnu/libasan.so.3+0x30f59)
#1 0x7fde9dc9a94b in epicsThreadCreate ../../../src/libCom/osi/os/posix/osdThread.c:516

Thread T6 (CAC-UDP) created by T3 (QThread) here:
#0 0x7fde9ed03f59 in __interceptor_pthread_create (/usr/lib/x86_64-linux-gnu/libasan.so.3+0x30f59)
#1 0x7fde9dc9a94b in epicsThreadCreate ../../../src/libCom/osi/os/posix/osdThread.c:516

SUMMARY: AddressSanitizer: alloc-dealloc-mismatch (/usr/lib/x86_64-linux-gnu/libasan.so.3+0xc37f0) in operator delete(void*, unsigned long)

@vakond
Copy link
Author

vakond commented Jan 24, 2019

Looks like some instances were created with new[], but deleted with just delete (should be delete[]).

For example:
// Allocation
void Generic::setLong( qint32* newValueArray, unsigned long arrayCountIn ) {
deleteValue();
value = new qint32[arrayCountIn]; <---- HERE
if( newValueArray )
{
memcpy( value, newValueArray, sizeof(qint32)*arrayCountIn );
}
arrayCount = arrayCountIn;
type = GENERIC_LONG;
}

// Deallocation
void Generic::deleteValue() {
...
switch( getType() ) {
...
case GENERIC_LONG :
delete (qint32*)value; <---- HERE
break;
...
}
value = NULL;
type = GENERIC_UNKNOWN;
}

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

No branches or pull requests

1 participant