[ros-dev] [ros-diffs] [hbelusca] 71692: [SUBST]: CORE-10681 #comment Apply part of Peter Hater's patch proposed in CORE-10681, that is, fixing the usage of QueryDosDevice API, but without the new IsDriveUsed functionali...

Thomas Faber thomas.faber at reactos.org
Wed Jun 29 08:04:13 UTC 2016


On 2016-06-28 21:21, hbelusca at svn.reactos.org wrote:
> --- trunk/reactos/base/system/subst/subst.c	[iso-8859-1] (original)
> +++ trunk/reactos/base/system/subst/subst.c	[iso-8859-1] Tue Jun 28 19:21:08 2016
> @@ -75,81 +75,71 @@
>      if (_tcslen(Drive) > 2)
>          return FALSE;
>  
> -    dwSize = sizeof(TCHAR) * MAX_PATH;
> -    lpTargetPath = (LPTSTR) malloc(sizeof(TCHAR) * MAX_PATH);
> -    if ( lpTargetPath)
> -    {
> +    dwSize = MAX_PATH;
> +    lpTargetPath = (LPTSTR)malloc(sizeof(TCHAR) * dwSize);
> +    if (!lpTargetPath)
> +        return FALSE;
> +
> +    CharCount = QueryDosDevice(Drive,
> +                               lpTargetPath,
> +                               dwSize);
> +    while (!CharCount &&
> +           GetLastError() == ERROR_INSUFFICIENT_BUFFER)
> +    {
> +        lpTargetPath = (LPTSTR)realloc(lpTargetPath, sizeof(TCHAR) * dwSize);

This is not how you use realloc, this causes a memory leak in case of
failure.
Also, why is there a cast here (also, for malloc above)?

Thanks.
-Thomas

> +        if (lpTargetPath)
> +        {
> +            CharCount = QueryDosDevice(Drive,
> +                                       lpTargetPath,
> +                                       dwSize);
> +        }
> +    }
> +
> +    if (CharCount)
> +    {
> +        Result = _tcsncmp(lpTargetPath, _T("\\??\\"), 4) == 0 &&
> +            ( (lpTargetPath[4] >= _T('A') &&
> +            lpTargetPath[4] <= _T('Z')) ||
> +             (lpTargetPath[4] >= _T('a') &&
> +            lpTargetPath[4] <= _T('z')) );
> +    }
> +
> +    free(lpTargetPath);
> +
> +    return Result;
> +}




More information about the Ros-dev mailing list