using asprintf to avoid memleaks