msvc crashing with block .. was not allocated by _aligned routines, use free()

50 views
Skip to first unread message

Miro Karpis

unread,
Jun 20, 2023, 4:21:14 PM6/20/23
to Crypto++ Users
Hi,
This one is giving me really hard time. I'm trying to build crypto++ with msvc / windows - compilation works fine, but always when I want to use the lib I keep getting

 block at 0x000001362708B180 was not allocated by _aligned routines, use free()

After debugging the code I can see that the problem is in allocate.cpp 

void AlignedDeallocate(void *p)
{
// Guard pointer due to crash on AIX when CRYPTOPP_NO_ALIGNED_ALLOC
// is in effect. The guard was previously in place in SecBlock,
// but it was removed at f4d68353ca7c as part of GH #875.
CRYPTOPP_ASSERT(p);

if (p != NULLPTR)
{
#ifdef CRYPTOPP_MM_MALLOC_AVAILABLE
_mm_free(p);
#elif defined(CRYPTOPP_NO_ALIGNED_ALLOC)
p = (byte *)p - ((byte *)p)[-1];
free(p);
#else
free(p);
#endif
}
}

If I understand it correctly then the allocation wasn't done with aligned, but with malloc?
Did anyone had similar issue?

Just on the side I'm of course hitting the old, where _MSC_VER and __clang__ are defined. SO far I haven't find any workaround on this either.

// discussed at http://github.com/weidai11/cryptopp/issues/147.
#if (defined(_MSC_VER) && defined(__clang__) && \
   !(defined( __clang_analyzer__)) && !defined(__INTEL_LLVM_COMPILER))
# error: "Unsupported configuration"
#endif 


Will be more than thankful for any kind of help in this.

Regards,
/m

Jeffrey Walton

unread,
Jun 21, 2023, 1:16:45 AM6/21/23
to cryptop...@googlegroups.com
Yeah, that's the age-old Clang bug. Clang pretends to be other
compilers via #defines, but then it cannot consume the program for the
compiler it is pretending to be.

We have code paths setup for Clang. Clang needs to stop pretending to
be other compilers, and stay in its own lane.

File a bug report against Clang for it. Or don't use Clang in this case.

Jeff

Miro Karpis

unread,
Jun 21, 2023, 1:11:25 PM6/21/23
to Crypto++ Users
Hi, I mentioned above that I'm building with msvc not clang.

Jeffrey Walton

unread,
Jun 21, 2023, 1:19:29 PM6/21/23
to cryptop...@googlegroups.com
On Wed, Jun 21, 2023 at 1:11 PM Miro Karpis <mirosla...@gmail.com> wrote:
>
> Hi, I mentioned above that I'm building with msvc not clang.

On Windows you should be in the CRYPTOPP_MM_MALLOC_AVAILABLE path. See
https://github.com/weidai11/cryptopp/blob/master/config_align.h#L44 .

Please provide a minimum reproducer with the steps to duplicate the problem.

Jeff
Reply all
Reply to author
Forward
Message has been deleted
0 new messages