The DecrResultSetRefCount macro post-decrements the refcount when comparing to 0, so the test never succeeds (unless there is some bug that decrements result sets below 0).  If the test:

if ((rs->refCount--) <= 0) {

is changed to match the tdbcpostgres version:

if (--(rs->refCount) <= 0) {

Then the result sets are properly deleted (and the statement / connection structures' refcounts properly managed)