Fix memory leaks in stream pipeline