fix: need to free memory if NULL is returned