Pregunta

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.

¿Fue útil?

Solución

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;
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top