Skip to content

Commit edf31c8

Browse files
committed
Try Try to fix some memory leaks.
1 parent b35e272 commit edf31c8

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

pygpu/gpuarray.pyx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1428,6 +1428,7 @@ cdef GpuArray pygpu_reshape(GpuArray a, unsigned int nd, const size_t *newdims,
14281428
tot *= newdims[i]
14291429
cdims = <size_t *>calloc(nd, sizeof(size_t))
14301430
if cdims == NULL:
1431+
free(cdims)
14311432
raise MemoryError, "could not allocate cdims"
14321433

14331434
cdef size_t d
@@ -1437,10 +1438,12 @@ cdef GpuArray pygpu_reshape(GpuArray a, unsigned int nd, const size_t *newdims,
14371438
d = a.size // tot
14381439

14391440
if d * tot != a.size:
1441+
free(cdims)
14401442
raise GpuArrayException, "..."
14411443
cdims[i] = d
14421444

14431445
array_reshape(res, a, nd, cdims, ord, nocopy)
1446+
free(cdims)
14441447
return res
14451448

14461449

src/cache/disk.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,15 @@ static int key_path(disk_cache *c, const cache_key_t key, char *out) {
216216
unsigned char hash[64];
217217
int i;
218218

219-
if (c->kwrite(&kb, key)) return -1;
220-
if (Skein_512((unsigned char *)kb.s, kb.l, hash)) return -1;
219+
if (c->kwrite(&kb, key)) {
220+
strb_clear(&kb);
221+
return -1;
222+
}
223+
if (Skein_512((unsigned char *)kb.s, kb.l, hash)) {
224+
strb_clear(&kb);
225+
return -1;
226+
}
227+
strb_clear(&kb);
221228
if (snprintf(out, 10, "%02x%02x/%02x%02x",
222229
hash[0], hash[1], hash[2], hash[3]) != 9)
223230
return -1;

src/gpuarray_elemwise.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -738,18 +738,24 @@ GpuElemwise *GpuElemwise_new(gpucontext *ctx,
738738

739739
void GpuElemwise_free(GpuElemwise *ge) {
740740
unsigned int i;
741-
for (i = 0; i < ge->nd; i++) {
742-
if (k_initialized(&ge->k_basic_32[i]))
743-
GpuKernel_clear(&ge->k_basic_32[i]);
744-
if (k_initialized(&ge->k_basic[i]))
745-
GpuKernel_clear(&ge->k_basic[i]);
746-
}
741+
if (ge->k_basic_32 != NULL)
742+
for (i = 0; i < ge->nd; i++) {
743+
if (k_initialized(&ge->k_basic_32[i]))
744+
GpuKernel_clear(&ge->k_basic_32[i]);
745+
}
746+
if (ge->k_basic != NULL)
747+
for (i = 0; i < ge->nd; i++) {
748+
if (k_initialized(&ge->k_basic[i]))
749+
GpuKernel_clear(&ge->k_basic[i]);
750+
}
747751
if (ge->strides != NULL)
748752
for (i = 0; i < ge->narray; i++) {
749753
free(ge->strides[i]);
750754
}
751755
if (k_initialized(&ge->k_contig))
752756
GpuKernel_clear(&ge->k_contig);
757+
free(ge->k_basic_32);
758+
free(ge->k_basic);
753759
free_args(ge->n, ge->args);
754760
free((void *)ge->preamble);
755761
free((void *)ge->expr);

0 commit comments

Comments
 (0)