wordexp 失败时我们需要调用 wordfree 吗?在某些情况下,调用 wordfree 似乎会出现段错误(例如,当 wordfree 返回字符串为“foo 'bar”的错误代码时)。
这在手册页中并不清楚,我已经看到在某些错误情况下使用了 wordfree。
根据GNU 的手册示例 http://www.gnu.org/software/libc/manual/html_node/Wordexp-Example.html,只有在出现错误时才应调用它WRDE_NOSPACE
被返回:
switch (wordexp (program, &result, 0))
{
case 0: /* Successful. */
break;
case WRDE_NOSPACE:
/* If the error was WRDE_NOSPACE,
then perhaps part of the result was allocated. */
wordfree (&result);
default: /* Some other error. */
return -1;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)