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

aligned_malloc() calls unaligned std::malloc() #1651

Closed
Chungzuwalla opened this issue Jul 15, 2016 · 1 comment
Closed

aligned_malloc() calls unaligned std::malloc() #1651

Chungzuwalla opened this issue Jul 15, 2016 · 1 comment

Comments

@Chungzuwalla
Copy link

Due to a bug in pcl_macros.h, aligned_malloc() will always call (the possibly unaligned) std::malloc(), regardless of the platform or configuration flags. On 32-bit Windows at least, this will cause a crash.
offending code
MALLOC_ALIGNED is #defined as 0 or 1 depending on whether std::malloc() is believed to be aligned. However, the implementation of aligned_malloc() only tests whether MALLOC_ALIGNED is #defined, which it always is. Therefore, std::malloc() is always used, even when MALLOC_ALIGNED is 0.

Your Environment

  • Operating System and version: Windows 7 x64
  • Compiler: Visual C++ 2015
  • PCL Version: 1.8

Expected Behavior

aligned_malloc() returns memory with 16-byte alignment on Win32.

Current Behavior

aligned_malloc() returns memory with 8-byte alignment on Win32, causing a crash.

Possible Solution

define MALLOC_ALIGNED only when std::malloc() is believed to be aligned.

i.e.:

#if defined(__APPLE__) || defined(_WIN64) || GLIBC_MALLOC_ALIGNED || FREEBSD_MALLOC_ALIGNED
#define MALLOC_ALIGNED
#endif

stefanbuettner added a commit to stefanbuettner/pcl that referenced this issue Jul 29, 2016
…turn aligned memory

See PointCloudLibrary#1651.
On 32-bit Windows, for example, aligned_malloc did not use aligned
memory allocation due to wrong preprocessor definitions.
Sets ALIGNED_MALLOC to 1 in case someone really checked that value.
@stefanbuettner
Copy link
Contributor

Hi Chungzuwalla,

looks like a bug indeed. Thanks for the notification. I'll file a fix.

Cheers,
Stefan

SergioRAgostinho added a commit that referenced this issue Aug 18, 2016
Fixes issue #1651: aligned_malloc does not always return aligned memory
SergioRAgostinho pushed a commit to SergioRAgostinho/pcl that referenced this issue Aug 19, 2016
…turn aligned memory

See PointCloudLibrary#1651.
On 32-bit Windows, for example, aligned_malloc did not use aligned
memory allocation due to wrong preprocessor definitions.
Sets ALIGNED_MALLOC to 1 in case someone really checked that value.
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

3 participants