apache / celix

Apache Celix is a framework for C and C++14 to develop dynamic modular software applications using component and in-process service-oriented programming.
https://celix.apache.org/
Apache License 2.0
165 stars 86 forks source link

Memory Leaks Caused By realloc Failure #730

Closed PengZheng closed 7 months ago

PengZheng commented 7 months ago

As mentioned in https://github.com/apache/celix/pull/727#discussion_r1487909520, the following code will leak the original memory block in case of realloc failure:

    seq->buf = realloc(seq->buf, (size_t)(cap * size));
    if (seq->buf == NULL) {
        seq->cap = 0;
        celix_err_pushf("Error allocating memory for seq buf");
        return MEM_ERROR;
    }

According to the manual page:

If realloc() fails, the original block is left untouched; it is not freed or moved.