Pádraig Brady <[email protected]> writes:

> On 01/02/2026 20:34, Collin Funk wrote:
>> I couldn't get this to overflow the stack, since passing a large file
>> name will run into ENAMETOOLONG errors before find_mount_point is
>> executed. But as far as I can tell, this strdupa call was never needed.
>
> Yes the explicit free() calls aren't too onerous here,
> as the "dir" is only used within this else clause.

You could increase the scope of dir, and initialize it to NULL, so that
calling free is always safe. I.e., written like this:

    extern char *
    find_mount_point (char const *file, struct stat const *file_stat)
    {
      char *dir = NULL;
      if (...)
        {
          /* This branch doesn't use DIR.  */
        }
      else
        {
          dir = dir_name (file);

          if (...)
            {
              /* Some error occurs.  */
              goto done;
            }
        }

    done:
      free (dir)
      /* ...  */
    }

But I find reducing the scope increases clarity more than reducing the
number of calls to free.

> I wouldn't change for this release though,
> just in case.

Yep, I was thinking the same. I'll push it after.

Collin

Reply via email to