unique_ptr and allocator combination cause "Unhandled exception at (ntdll.dll) Python.exe: A heap has been corrupted #1592

paxRomana99 opened this Issue Jan 25, 2017 · 1 comment


None yet

1 participant

paxRomana99 commented Jan 25, 2017 edited

The following code causes a heap corrupted error once the array size grows to a certain point.

import numpy as np
cimport numpy as np
from libcpp.memory cimport unique_ptr, allocator

def testArray1(int dim1):
    cdef allocator[double] dbl_al
    cdef unique_ptr[double] myptr


def testArray2(int dim1, int dim2):
    cdef allocator[double *] ptr_al
    cdef np.ndarray arr
    cdef double[:,:] carr
    cdef unique_ptr[double *] myptr

    arr = np.ndarray((dim1,dim2),dtype=np.float64,order='C')
    carr = arr

    myptr.get()[0] = &carr[0,0]
    myptr.get()[1] = &carr[1,0]
    myptr.get()[2] = &carr[2,0]

Calling testArray1(511) or testArray2(511,1000) works fine. Calling testArray1(512) or testArray2(512,1000) causes a crash with the heap corrupted notification. This was observed for Cython 24.1, Python 3.5.1, VS2015, Windows 7 SP1.

paxRomana99 commented Jan 27, 2017 edited

Looks like it might be a Windows issue. It has been tested on Linux for Python 2.7 with Cython 25.2 and Python 3.5 with Cython 24.1 and neither encountered the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment