Skip to content
This repository was archived by the owner on Aug 21, 2025. It is now read-only.
This repository was archived by the owner on Aug 21, 2025. It is now read-only.

Failure to free memory return from CommandLineToArgvW() in ParseCommandLine() results in leak #1

@JohnLaTwC

Description

@JohnLaTwC

ParseCommandLine() calls CommandLineToArgvW. The returned string must be freed by the caller with LocalFree.

BOOL ParseCommandLine()
{
    LPWSTR pwszCommandLine = GetCommandLine();
    LPWSTR* argv = NULL;
    int argc = 0;
    int i = 0;

!    argv = CommandLineToArgvW(pwszCommandLine, &argc);  <<< this memory must be freed with LocalFree
    if (!argv)
        return FALSE;
...

if (argc < 2)

See https://docs.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-commandlinetoargvw:
CommandLineToArgvW allocates a block of contiguous memory for pointers to the argument strings, and for the argument strings themselves; the calling application must free the memory used by the argument list when it is no longer needed. To free the memory, use a single call to the LocalFree function.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions