in reply to ct_cmd_alloc failed

That's a lot of code to ask us to read through. And you don't tell us basic information like what driver/RDBMS you are using. But a simple search turns up this possibly helpful tidbit.