Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion numpy/_core/src/multiarray/arrayobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -442,9 +442,9 @@ array_dealloc(PyArrayObject *self)
nbytes = 1;
}
PyDataMem_UserFREE(fa->data, nbytes, fa->mem_handler);
Py_DECREF(fa->mem_handler);
}
}
Py_CLEAR(fa->mem_handler);

/* must match allocation in PyArray_NewFromDescr */
npy_free_cache_dim(fa->dimensions, 2 * fa->nd);
Expand Down
12 changes: 8 additions & 4 deletions numpy/_core/src/multiarray/ctors.c
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,13 @@ PyArray_NewFromDescr_int(
raise_memory_error(fa->nd, fa->dimensions, descr);
goto fail;
}
/*
* Set fa->data and NPY_ARRAY_OWNDATA immediately after allocation so
* that the fail path (Py_DECREF(fa) -> dealloc) frees the buffer if
* the fill-zero loop below raises an error.
*/
fa->data = data;
fa->flags |= NPY_ARRAY_OWNDATA;

/*
* If the array needs special dtype-specific zero-filling logic, do that
Expand All @@ -919,8 +926,6 @@ PyArray_NewFromDescr_int(
goto fail;
}
}

fa->flags |= NPY_ARRAY_OWNDATA;
}
else {
/* The handlers should never be called in this case */
Expand All @@ -929,8 +934,8 @@ PyArray_NewFromDescr_int(
* If data is passed in, this object won't own it.
*/
fa->flags &= ~NPY_ARRAY_OWNDATA;
fa->data = data;
}
fa->data = data;

/*
* Always update the aligned flag. Not owned data or input strides may
Expand Down Expand Up @@ -998,7 +1003,6 @@ PyArray_NewFromDescr_int(

fail:
NPY_traverse_info_xfree(&fill_zero_info);
Py_XDECREF(fa->mem_handler);
Py_DECREF(fa);
return NULL;
}
Expand Down
Loading