问题
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.
回答1:
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;
}
来源:https://stackoverflow.com/questions/23120084/do-we-need-to-call-wordfree-upon-wordexp-failure