Bugfixes for memory leaks

Disallow sending command without callback: too error-prone.

Ensure callback for heartbeat is called.

Ensure handler is freed.