我们需要在wordexp失败时调用wordfree吗?

4
我们需要在wordexp失败时调用wordfree吗?在某些情况下调用wordfree似乎会导致分段错误(例如,当wordfree返回带有字符串“foo'bar”的错误代码时)。这在手册页中并不清楚,并且我曾经在一些错误情况下看到过wordfree的使用。
1个回答

4
根据GNU手册示例,只有在返回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;
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接