下面的程序会造成内存泄露吗?如果是的话,应该如何改进?
acqy 2005-06-16 09:09:22 char *LeftStr(const char *_str, int _pos)
{
char *buffer;
if (_pos <= 0 || _pos >= strlen(_str))
{
return (char *)_str;
}
buffer = new char[strlen(_str) + 1];
strncpy (buffer, _str, _pos);
return buffer;
}