Skip to content
This repository was archived by the owner on Feb 18, 2020. It is now read-only.

Commit 5871d84

Browse files
Memory Leaks
1 parent ac3faf2 commit 5871d84

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

kernel/calculation.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,13 +228,13 @@ CArray_Prod(CArray * self, int * axis, int rtype, MemoryPointer * out_ptr)
228228
ret = (CArray *)emalloc(sizeof(CArray));
229229
descr = (CArrayDescriptor*)emalloc(sizeof(CArrayDescriptor));
230230
arr = CArray_CheckAxis(self, axis, 0);
231-
int index_jumps = self->strides[*axis]/self->descriptor->elsize;
232231

233232
if(axis != NULL) {
234233
if(*axis >= CArray_NDIM(self)) {
235234
throw_axis_exception("Invalid axis for current matrix shape.");
236235
return NULL;
237236
}
237+
int index_jumps = self->strides[*axis] / self->descriptor->elsize;
238238
}
239239

240240
if (arr == NULL) {
@@ -262,7 +262,6 @@ CArray_Prod(CArray * self, int * axis, int rtype, MemoryPointer * out_ptr)
262262
if(axis == NULL) {
263263
descr->numElements = 1;
264264
ret = CArray_NewFromDescr_int(ret, descr, 0, NULL, NULL, NULL, 0, NULL, 1, 0);
265-
CArray_Data_alloc(ret);
266265
if(rtype == TYPE_INTEGER_INT) {
267266
*((int*)total) = IDATA(self)[0];
268267
for(i = 1; i < CArray_DESCR(self)->numElements; i++) {

kernel/linalg.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,6 @@ CArray_Matmul(CArray * ap1, CArray * ap2, CArray * out, MemoryPointer * ptr)
239239
CArrayIterator_FREE(it1);
240240
CArrayIterator_FREE(it2);
241241

242-
if(ptr != NULL) {
243-
add_to_buffer(ptr, result, sizeof(CArray*));
244-
}
245242
efree(dimensions);
246243
// Remove appended dimension
247244
result->ndim = ap1->ndim;
@@ -496,6 +493,7 @@ CArray_Det(CArray * a, MemoryPointer * out)
496493
efree(data);
497494
}
498495

496+
efree(ipiv);
499497
return rtn;
500498
fail:
501499
return NULL;
@@ -712,8 +710,8 @@ CArray_Svd(CArray * a, int full_matrices, int compute_uv, MemoryPointer * out)
712710
target = a;
713711
}
714712

713+
data = emalloc(sizeof(double) * CArray_SIZE(a));
715714
if (!CArray_CHKFLAGS(a, CARRAY_ARRAY_C_CONTIGUOUS)) {
716-
data = emalloc(sizeof(double) * CArray_SIZE(a));
717715
linearize_DOUBLE_matrix(data, DDATA(target), target);
718716
} else {
719717
memcpy(data, DDATA(target), sizeof(double) * CArray_SIZE(target));

phpsci.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ PHP_METHOD(CArray, arcsin)
525525
ZEND_PARSE_PARAMETERS_END();
526526
ZVAL_TO_MEMORYPOINTER(target, &ptr, NULL);
527527
target_ca = CArray_FromMemoryPointer(&ptr);
528-
ret = CArray_Tan(target_ca, &rtn_tr);
528+
ret = CArray_Arcsin(target_ca, &rtn_tr);
529529

530530
FREE_FROM_MEMORYPOINTER(&ptr);
531531
RETURN_MEMORYPOINTER(return_value, &rtn_tr);
@@ -542,7 +542,7 @@ PHP_METHOD(CArray, arccos)
542542
ZEND_PARSE_PARAMETERS_END();
543543
ZVAL_TO_MEMORYPOINTER(target, &ptr, NULL);
544544
target_ca = CArray_FromMemoryPointer(&ptr);
545-
ret = CArray_Tan(target_ca, &rtn_tr);
545+
ret = CArray_Arccos(target_ca, &rtn_tr);
546546

547547
FREE_FROM_MEMORYPOINTER(&ptr);
548548
RETURN_MEMORYPOINTER(return_value, &rtn_tr);
@@ -559,7 +559,7 @@ PHP_METHOD(CArray, arctan)
559559
ZEND_PARSE_PARAMETERS_END();
560560
ZVAL_TO_MEMORYPOINTER(target, &ptr, NULL);
561561
target_ca = CArray_FromMemoryPointer(&ptr);
562-
ret = CArray_Tan(target_ca, &rtn_tr);
562+
ret = CArray_Arctan(target_ca, &rtn_tr);
563563

564564
FREE_FROM_MEMORYPOINTER(&ptr);
565565
RETURN_MEMORYPOINTER(return_value, &rtn_tr);
@@ -1460,7 +1460,7 @@ PHP_METHOD(CArray, prod)
14601460
long axis;
14611461
int * axis_p;
14621462
CArray * ret, * target_ca;
1463-
MemoryPointer ptr;
1463+
MemoryPointer ptr, rtn_ptr;
14641464
ZEND_PARSE_PARAMETERS_START(1, 2)
14651465
Z_PARAM_ZVAL(target)
14661466
Z_PARAM_OPTIONAL
@@ -1475,9 +1475,11 @@ PHP_METHOD(CArray, prod)
14751475
}
14761476
ZVAL_TO_MEMORYPOINTER(target, &ptr, NULL);
14771477
target_ca = CArray_FromMemoryPointer(&ptr);
1478-
ret = CArray_Prod(target_ca, axis_p, target_ca->descriptor->type_num, &ptr);
1478+
ret = CArray_Prod(target_ca, axis_p, target_ca->descriptor->type_num, &rtn_ptr);
14791479
efree(axis_p);
1480-
RETURN_MEMORYPOINTER(return_value, &ptr);
1480+
1481+
FREE_FROM_MEMORYPOINTER(&ptr);
1482+
RETURN_MEMORYPOINTER(return_value, &rtn_ptr);
14811483
}
14821484

14831485
PHP_METHOD(CArray, cumprod)
@@ -1654,6 +1656,10 @@ PHP_METHOD(CArray, around)
16541656
return;
16551657
}
16561658

1659+
if (target_ptr.free == 1 || target_ptr.free == 2) {
1660+
CArrayDescriptor_INCREF(CArray_DESCR(rtn_ca));
1661+
}
1662+
16571663
FREE_FROM_MEMORYPOINTER(&target_ptr);
16581664
RETURN_MEMORYPOINTER(return_value, &rtn_ptr);
16591665
}
@@ -2744,7 +2750,7 @@ static zend_function_entry carray_class_methods[] =
27442750
PHP_ME(CArray, cosh, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
27452751
PHP_ME(CArray, tanh, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
27462752

2747-
// STORAGAE
2753+
// STORAGE
27482754
PHP_ME(CArray, save, NULL, ZEND_ACC_PUBLIC)
27492755
PHP_ME(CArray, load, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
27502756

0 commit comments

Comments
 (0)