NumPower / numpower

PHP extension for efficient scientific computing and array manipulation with GPU support
https://numpower.org
Other
192 stars 4 forks source link

fix: Fix NDArray::prod memory leak when using a PHP array as argument #29

Closed henrique-borba closed 1 year ago

henrique-borba commented 1 year ago

When calling nd::prod with a PHP function as below the temporary NDArray* nda is not freed automatically.

$a = nd::prod([[1, 2], [3, 4]]);

I added the code below to check and free the input before returning when only one argument is provided to the function

...
value = NDArray_Float_Prod(nda);
        CHECK_INPUT_AND_FREE(a, nda);  // Check if nda is temporary and free before return
        RETURN_DOUBLE(value);