resolve malloc memory problem (workaround version)