Svante Signell, on mar. 26 sept. 2017 16:15:06 +0200, wrote:
> + /* Relative path */
> + else
> + {
> + cwd = getcwd (NULL, 0);
> + if (cwd == NULL)
> + goto out;
> +
> + res = asprintf (&concat_name, "%s/%s", cwd, file);
That should be “filename” instead of “file”.
Take the case of PATH containing e.g. :bin: , and your current directory
contains a bin directory which contains a script and you pass only the
name of the script to spawni(). “file” would only contain the name
of the script, while “filename” would contain ./bin/
> + if (res == -1)
> + {
> + free (cwd);
In both cases you can just free(cwd) right after the asprintf call, to
make the whole code simpler, and also make the cwd variable local to the
corresponding blocks.
> + goto out;
> + }
> +
> + filename = concat_name;
> + break;
> + }