문제

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.

도움이 되었습니까?

해결책

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;
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top