Stack overflow on staticvector/matrix deallocation with vectorization off

Issue #129 resolved
Vojtěch Krs created an issue

I encountered this issue when trying to use StaticVector and StaticMatrix inside a DynamicVector or DynamicMatrix. One of the wiki examples has this issue also: example 3 here: Block Vectors and Matrices.

The issue is, when delete/delete[] is called on StaticVector/Matrix, there's an infinite loop between StaticVector delete operator and the deallocate() function.

It happens only when vectorization is off and using float as the stored type.

Here's a minimal example that triggers it:

#include "blaze/Blaze.h"

using namespace blaze;

int main(int argc, char **argv)
{
    auto v = std::make_unique<StaticVector<float, 3>>();
    return 0;
}

or

auto v = new StaticVector<float, 3>();
delete v;

Here's the stack for the latter example:

... repeats until stack overflow
    test.exe!blaze::deallocate<blaze::StaticVector<float,8,0> >(blaze::StaticVector<float,8,0> * address) Line 278  C++ Symbols loaded.
    test.exe!blaze::StaticVector<float,8,0>::operator delete[](void * ptr) Line 1703    C++ Symbols loaded.
    test.exe!blaze::deallocate<blaze::StaticVector<float,8,0> >(blaze::StaticVector<float,8,0> * address) Line 278  C++ Symbols loaded.
    test.exe!blaze::StaticVector<float,8,0>::operator delete(void * ptr) Line 1687  C++ Symbols loaded.
    test.exe!main(int argc, char * * argv) Line 10  C++ Symbols loaded.

The issue stems from a check at Memory.h::267

if( alignment >= 8UL )

which fails for float without vectorization.

Tested on VS2015 and VS2017.

PS: The linked example has a missing comma in the initializer list of matrix A.

Comments (3)

  1. Klaus Iglberger

    Hi Vojtech!

    Thanks a lot for pointing out this defect. We can reproduce the issue and will fix it immediately. Thanks also for taking the time to raise this issue, we wouldn't have found this defect without your help.

    Best regards,

    Klaus!

  2. Klaus Iglberger

    Commit 61a26eb resolves the possible recursive function call caused by the deallocate() function. The fix is immediately available via cloning the Blaze repository and will be officially released in Blaze 3.3.

  3. Log in to comment