malloc returned null pointer

147 views
Skip to first unread message

Jakob Clausen

unread,
Mar 8, 2021, 2:22:04 AM3/8/21
to cpputest

Hi.

I get the following error, when running the tests

test/LocalSocketTest.cpp:117: error: Failure in TEST(LocalSocketServer_systemtest, string)
src/CppUTest/TestMemoryAllocator.cpp:37: error:
    malloc returned null pointer

terminate called after throwing an instance of 'CppUTestFailedException'
Stack trace (most recent call last) in thread 7947:

This does not happen every time I run the tests - only about one fifth of the testruns fails in this way.
If I look at the stacktrace, then it looks like what is failing me is this function:

void SocketCommunication::newBufferSize(uint64_t size)
{
    if (size > totalSize)
    {
        totalSize = size;
        delete[] buffer;
        buffer = new char[totalSize];
    }
}

As the error is with malloc - I assume that it is new, that is failing me.
What could make malloc fail in this way?
I don't think I am out of memory.

Jakob.


Bas Vodde

unread,
Mar 8, 2021, 3:44:48 PM3/8/21
to cppu...@googlegroups.com

Is it multi-threaded code?

Bas

--
You received this message because you are subscribed to the Google Groups "cpputest" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cpputest+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cpputest/20fbd9e2-e244-4297-949a-b580a26d71d1n%40googlegroups.com.

Jakob Clausen

unread,
Mar 9, 2021, 1:00:08 AM3/9/21
to cpputest
Yes it is.

Bas Vodde

unread,
Mar 9, 2021, 2:35:47 AM3/9/21
to cppu...@googlegroups.com
Hi,

Then you might want to try:

MemoryLeakWarningPlugin::turnOnThreadSafeNewDeleteOverloads on your main and see if that makes a difference.

Thanks!

Bas

Jakob Clausen

unread,
Mar 9, 2021, 5:45:27 AM3/9/21
to cpputest
That looks like a very good idea. :-)
I guess I always would want that, when I go multithreaded?

It looks good.
I will test some more.

Jakob Clausen

unread,
Mar 9, 2021, 8:52:16 AM3/9/21
to cpputest
That seemed to do it.
Thank you very much.
Reply all
Reply to author
Forward
0 new messages