Skip to content

Commit 714f3a5

Browse files
committed
Manage free() with a try-catch block.
1 parent e3d4aa0 commit 714f3a5

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

pygpu/gpuarray.pyx

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1430,20 +1430,21 @@ cdef GpuArray pygpu_reshape(GpuArray a, unsigned int nd, const size_t *newdims,
14301430
if cdims == NULL:
14311431
raise MemoryError, "could not allocate cdims"
14321432

1433-
cdef size_t d
1434-
for i in range(nd):
1435-
d = newdims[i]
1436-
if i == caxis:
1437-
d = a.size // tot
1438-
1439-
if d * tot != a.size:
1440-
free(cdims)
1441-
raise GpuArrayException, "..."
1442-
cdims[i] = d
1433+
try:
1434+
cdef size_t d
1435+
for i in range(nd):
1436+
d = newdims[i]
1437+
if i == caxis:
1438+
d = a.size // tot
1439+
1440+
if d * tot != a.size:
1441+
raise GpuArrayException, "..."
1442+
cdims[i] = d
14431443

1444-
array_reshape(res, a, nd, cdims, ord, nocopy)
1445-
free(cdims)
1446-
return res
1444+
array_reshape(res, a, nd, cdims, ord, nocopy)
1445+
return res
1446+
finally:
1447+
free(cdims)
14471448

14481449

14491450
cdef GpuArray pygpu_transpose(GpuArray a, const unsigned int *newaxes):

0 commit comments

Comments
 (0)