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

C 我们需要在wordexp失败时调用wordfree吗?,c,posix,expansion,C,Posix,Expansion,我们需要在wordexp失败时调用wordfree吗?在某些情况下调用wordfree似乎是错误的(例如,wordfree返回的错误代码字符串为“foo”bar)。 这在手册页中并不清楚,我在一些错误案例中看到了wordfree的使用。根据,只有在返回WRDE_NOSPACE时,才应在出错时调用它: switch (wordexp (program, &result, 0)) { case 0: /* Successful. */ break; case WRDE_

我们需要在wordexp失败时调用wordfree吗?在某些情况下调用wordfree似乎是错误的(例如,wordfree返回的错误代码字符串为“foo”bar)。 这在手册页中并不清楚,我在一些错误案例中看到了wordfree的使用。

根据,只有在返回
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;
}