diff --git a/pygpu/gpuarray.pyx b/pygpu/gpuarray.pyx index 44608e1e4f..a1e38bc4cf 100644 --- a/pygpu/gpuarray.pyx +++ b/pygpu/gpuarray.pyx @@ -1431,17 +1431,20 @@ cdef GpuArray pygpu_reshape(GpuArray a, unsigned int nd, const size_t *newdims, raise MemoryError, "could not allocate cdims" cdef size_t d - for i in range(nd): - d = newdims[i] - if i == caxis: - d = a.size // tot + try: + for i in range(nd): + d = newdims[i] + if i == caxis: + d = a.size // tot - if d * tot != a.size: - raise GpuArrayException, "..." - cdims[i] = d + if d * tot != a.size: + raise GpuArrayException, "..." + cdims[i] = d - array_reshape(res, a, nd, cdims, ord, nocopy) - return res + array_reshape(res, a, nd, cdims, ord, nocopy) + return res + finally: + free(cdims) cdef GpuArray pygpu_transpose(GpuArray a, const unsigned int *newaxes): diff --git a/src/cache/disk.c b/src/cache/disk.c index 6fda751b30..0f9de82e0a 100644 --- a/src/cache/disk.c +++ b/src/cache/disk.c @@ -216,8 +216,15 @@ static int key_path(disk_cache *c, const cache_key_t key, char *out) { unsigned char hash[64]; int i; - if (c->kwrite(&kb, key)) return -1; - if (Skein_512((unsigned char *)kb.s, kb.l, hash)) return -1; + if (c->kwrite(&kb, key)) { + strb_clear(&kb); + return -1; + } + if (Skein_512((unsigned char *)kb.s, kb.l, hash)) { + strb_clear(&kb); + return -1; + } + strb_clear(&kb); if (snprintf(out, 10, "%02x%02x/%02x%02x", hash[0], hash[1], hash[2], hash[3]) != 9) return -1; diff --git a/src/gpuarray_buffer_cuda.c b/src/gpuarray_buffer_cuda.c index 9a99d749c9..99b9bbee31 100644 --- a/src/gpuarray_buffer_cuda.c +++ b/src/gpuarray_buffer_cuda.c @@ -1223,6 +1223,8 @@ static int compile(cuda_context *ctx, strb *src, strb* bin, strb *log) { GA_CHECK(make_bin(ctx, &ptx, bin, log)); + strb_clear(&ptx); + if (ctx->disk_cache) { pk = calloc(sizeof(disk_key), 1); if (pk == NULL) { @@ -1234,7 +1236,7 @@ static int compile(cuda_context *ctx, strb *src, strb* bin, strb *log) { memcpy(pk, &k, DISK_KEY_MM); strb_appendb(&pk->src, src); if (strb_error(&pk->src)) { - error_sys(ctx->err, "strb_appendb"); + error_sys(ctx->err, "strb_appendb"); fprintf(stderr, "Error adding kernel to disk cache %s\n", ctx->err->msg); disk_free((cache_key_t)pk); @@ -1242,7 +1244,7 @@ static int compile(cuda_context *ctx, strb *src, strb* bin, strb *log) { } cbin = strb_alloc(bin->l); if (cbin == NULL) { - error_sys(ctx->err, "strb_alloc"); + error_sys(ctx->err, "strb_alloc"); fprintf(stderr, "Error adding kernel to disk cache: %s\n", ctx->err->msg); disk_free((cache_key_t)pk); @@ -1250,7 +1252,7 @@ static int compile(cuda_context *ctx, strb *src, strb* bin, strb *log) { } strb_appendb(cbin, bin); if (strb_error(cbin)) { - error_sys(ctx->err, "strb_appendb"); + error_sys(ctx->err, "strb_appendb"); fprintf(stderr, "Error adding kernel to disk cache %s\n", ctx->err->msg); disk_free((cache_key_t)pk); diff --git a/src/gpuarray_elemwise.c b/src/gpuarray_elemwise.c index 3ba31d30fe..fa5b0efa2c 100644 --- a/src/gpuarray_elemwise.c +++ b/src/gpuarray_elemwise.c @@ -738,18 +738,24 @@ GpuElemwise *GpuElemwise_new(gpucontext *ctx, void GpuElemwise_free(GpuElemwise *ge) { unsigned int i; - for (i = 0; i < ge->nd; i++) { - if (k_initialized(&ge->k_basic_32[i])) - GpuKernel_clear(&ge->k_basic_32[i]); - if (k_initialized(&ge->k_basic[i])) - GpuKernel_clear(&ge->k_basic[i]); - } + if (ge->k_basic_32 != NULL) + for (i = 0; i < ge->nd; i++) { + if (k_initialized(&ge->k_basic_32[i])) + GpuKernel_clear(&ge->k_basic_32[i]); + } + if (ge->k_basic != NULL) + for (i = 0; i < ge->nd; i++) { + if (k_initialized(&ge->k_basic[i])) + GpuKernel_clear(&ge->k_basic[i]); + } if (ge->strides != NULL) for (i = 0; i < ge->narray; i++) { free(ge->strides[i]); } if (k_initialized(&ge->k_contig)) GpuKernel_clear(&ge->k_contig); + free(ge->k_basic_32); + free(ge->k_basic); free_args(ge->n, ge->args); free((void *)ge->preamble); free((void *)ge->expr);