[PATCH v3] kdb: Make memory allocations more robust