Fixed memory leaks in cumsum and cumprod.
Merge pull request #1737 from MarcCote/cumsum_memoryleak

Fixed memory leaks in cumsum and cumprod.