Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[hotconv] 'name': memory leak in addName() #1643

Closed
NSGod opened this issue Apr 19, 2023 · 0 comments · Fixed by #1646
Closed

[hotconv] 'name': memory leak in addName() #1643

NSGod opened this issue Apr 19, 2023 · 0 comments · Fixed by #1646

Comments

@NSGod
Copy link
Contributor

NSGod commented Apr 19, 2023

I think I may have found a leak in name.c -> addName()

In name.c, line 168:

static void addName(nameCtx h,
                    unsigned short platformId,
                    unsigned short platspecId,
                    unsigned short languageId,
                    unsigned short nameId,
                    size_t length, char *str) {
    char *dst;
    char *newStr;
    newStr = MEM_NEW(h->g, length * sizeof(char)); <<-- ALLOCATED
    NameRecord *rec;
    int index;
    int omitMacNames = (h->g->convertFlags & HOT_OMIT_MAC_NAMES); /* omit all Mac platform names. */

    if (platformId == HOT_NAME_MAC_PLATFORM) {
        if (omitMacNames)
            return;
    }

    if (omitMacNames && (platformId == HOT_NAME_MAC_PLATFORM)) {
        return;
    }

First, it looks like the last 3 lines — and the 4 lines before that — effectively do the same thing: return early if it's Mac and we're not writing Mac platform names. However, newStr is allocated before that return and not released until near the end of the function, which would cause a leak, I believe.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant