Use snprintf instead of sprintf() to avoid writing beyound the string buffer.
strchr() may return NULL if the @ is not found. And of course: snprintf.
Fixed some memory leaks in error cases.
Updated git ignore.