8000 Pull request #70: Fix leak due to HPyArray_NewFromDescr · hpyproject/numpy-hpy@3423d65 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3423d65

Browse files
committed
Pull request numpy#70: Fix leak due to HPyArray_NewFromDescr
Merge in ~STEPAN.SINDELAR_ORACLE.COM/numpy-hpy from fa/fix_leak_newfromdescr to labs-hpy-port * commit 'd86aa3b8358555ab4bf8620ec0156f3664e66000': Fix leak due to HPyArray_NewFromDescr
2 parents 7dc6242 + d86aa3b commit 3423d65

File tree

4 files changed

+7
-1
lines changed

4 files changed

+7
-1
lines changed

numpy/core/src/multiarray/arrayobject.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,7 @@ HPyArray_CopyObject(HPyContext *ctx, HPy h_dest, PyArrayObject *dest, HPy h_src_
455455
PyArray_FLAGS(dest) & NPY_ARRAY_F_CONTIGUOUS, HPy_NULL);
456456
HPy_Close(ctx, hpy_arr_type);
457457
if (HPy_IsNull(h_view)) {
458+
HPy_Close(ctx, h_dtype);
458459
npy_free_coercion_cache(cache);
459460
return -1;
460461
}

numpy/core/src/multiarray/ctors.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,6 +1353,7 @@ HPyArray_NewLikeArrayWithShape(HPyContext *ctx, HPy prototype, NPY_ORDER order,
13531353
ret = HPyArray_NewFromDescr(ctx, type, dtype, ndim, dims, NULL, NULL,
13541354
order, subok ? prototype : HPy_NULL);
13551355
HPy_Close(ctx, type);
1356+
HPy_Close(ctx, dtype);
13561357
}
13571358
/* KEEPORDER needs some analysis of the strides */
13581359
else {
@@ -2019,6 +2020,7 @@ HPyArray_FromAny(HPyContext *ctx, HPy op, HPy newtype, int min_depth,
20192020
array_type, dtype, ndim, dims, NULL, NULL,
20202021
flags & NPY_ARRAY_F_CONTIGUOUS, HPy_NULL);
20212022
HPy_Close(ctx, array_type);
2023+
HPy_Close(ctx, dtype);
20222024
if (HPy_IsNull(ret)) {
20232025
return HPy_NULL;
20242026
}

numpy/core/src/multiarray/item_selection.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2669,10 +2669,12 @@ HPyArray_Nonzero(HPyContext *ctx, HPy h_self)
26692669
ret_dims[0] = nonzero_count;
26702670
ret_dims[1] = ndim;
26712671
HPy arr_type = HPyGlobal_Load(ctx, HPyArray_Type);
2672+
HPy tmp_dtype = HPyArray_DescrFromType(ctx, NPY_INTP);
26722673
h_ret = HPyArray_NewFromDescr(
2673-
ctx, arr_type, HPyArray_DescrFromType(ctx, NPY_INTP),
2674+
ctx, arr_type, tmp_dtype,
26742675
2, ret_dims, NULL, NULL,
26752676
0, HPy_NULL);
2677+
HPy_Close(ctx, tmp_dtype);
26762678
HPy_Close(ctx, arr_type);
26772679
if (HPy_IsNull(h_ret)) {
26782680
return HPy_NULL;

numpy/core/src/multiarray/scalarapi.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,7 @@ HPyArray_FromScalar(HPyContext *ctx, HPy h_scalar, /*PyArray_Descr*/ HPy h_outco
513513
0, NULL,
514514
NULL, NULL, 0, HPy_NULL);
515515
HPy_Close(ctx, h_PyArray_Type);
516+
HPy_Close(ctx, h_typecode); /* no longer needed */
516517

517518
if (HPy_IsNull(h_r)) {
518519
return HPy_NULL;

0 commit comments

Comments
 (0)
0