Question

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.

Was it helpful?

Solution

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;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top