8000 FIX: protect stolen ref by PyArray_NewFromDescr in array_empty by rainwoodman · Pull Request #8180 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

FIX: protect stolen ref by PyArray_NewFromDescr in array_empty #8180

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

Merged
merged 1 commit into from
Oct 20, 2016
Merged
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
8000
Diff view
15 changes: 11 additions & 4 deletions numpy/core/src/multiarray/ctors.c
Original file line number Diff line number Diff line change
Expand Up @@ -2895,20 +2895,27 @@ PyArray_Empty(int nd, npy_intp *dims, PyArray_Descr *type, int is_f_order)
PyArrayObject *ret;

if (!type) type = PyArray_DescrFromType(NPY_DEFAULT_TYPE);

/*
* PyArray_NewFromDescr steals a ref,
* but we need to look at type later.
* */
Py_INCREF(type);

ret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type,
type, nd, dims,
NULL, NULL,
is_f_order, NULL);
if (ret == NULL) {
return NULL;
}
if (PyDataType_REFCHK(type)) {
if (ret != NULL && PyDataType_REFCHK(type)) {
PyArray_FillObjectArray(ret, Py_None);
if (PyErr_Occurred()) {
Py_DECREF(ret);
Py_DECREF(type);
return NULL;
}
}

Py_DECREF(type);
return (PyObject *)ret;
}

Expand Down
0