fix whc memory allocation bugs