我们需要在 wordexp 失败时调用 wordfree 吗? [英] Do we need to call wordfree upon wordexp failure?

查看:61
本文介绍了我们需要在 wordexp 失败时调用 wordfree 吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们需要在 wordexp 失败时调用 wordfree 吗?在某些情况下,调用 wordfree 似乎会出现段错误(例如,当 wordfree 返回错误代码且字符串为foo 'bar"时).这在手册页中并不清楚,我已经看到在某些错误情况下使用 wordfree.

Do we need to call wordfree upon wordexp failure? Calling wordfree seems to segfault in some cases (eg when wordfree returns error code with string is "foo 'bar"). This isn't clear from man page, and I've seen wordfree used in some error cases.

推荐答案

根据 GNU 的手动示例,只有在返回 WRDE_NOSPACE 时才应在出错时调用它:

According to the GNU's manual example, it should be called on error only if WRDE_NOSPACE was returned:

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;
}

这篇关于我们需要在 wordexp 失败时调用 wordfree 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆