Skip to content

Memory leak in s2n_realloc #181

@keith-rollin

Description

@keith-rollin

I'm just eyeballing this so perhaps I'm missing something, but the following code in s2n_realloc seems to leak any old buffer in b->data:

    ...
    // Allocate new memory block.
    void *data;
    if (posix_memalign(&data, page_size, allocate)) {
        S2N_ERROR(S2N_ERR_ALLOC);
    }

    // Copy old data to new data. Check the size first so that we don't copy
    // from NULL (may want to test b->data instead?)
    if (b->size) {
        memcpy_check(data, b->data, b->size);
    }

    // Assign new data to `b`. NOTE: OLD b->data NOT CLEANED UP FIRST!
    b->data = data;
    b->size = size;
    b->allocated = allocate;
    ...

This code was introduced in 3a418cc as part of aligning the data buffer to a page size.

If there is a problem here that needs to be fixed, please also note the other reported issue regarding a lack of a call to munlock when freeing a block.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions