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

bug:static int merge_free_chunk(MemoryPool* mp, _MP_Memory* mm, _MP_Chunk* c) #15

Open
Zhichao-Yan opened this issue Apr 10, 2024 · 1 comment
Assignees
Labels
wontfix This will not be worked on

Comments

@Zhichao-Yan
Copy link

static int merge_free_chunk(MemoryPool* mp, _MP_Memory* mm, _MP_Chunk* c) {
    _MP_Chunk *p0 = c, *p1 = c;
    while (p0->is_free) {
        p1 = p0;
        // bug:向前面搜索邻接内存块貌似有错?p0是作为内存块_MP_Chunk首地址,而不是分配给用户的内存空间的首地址,因此不应该减去MP_CHUNKHEADER
        // ++if ((char*) p0  - MP_CHUNKHEADER <= mm->start) break;
        // --if ((char*) p0 - MP_CHUNKEND - MP_CHUNKHEADER <= mm->start) break;
        p0 = *(_MP_Chunk**) ((char*) p0 - MP_CHUNKEND);
    }

    p0 = (_MP_Chunk*) ((char*) p1 + p1->alloc_mem);
    while ((char*) p0 < mm->start + mp->mempool_size && p0->is_free) {
        MP_DLINKLIST_DEL(mm->free_list, p0);
        p1->alloc_mem += p0->alloc_mem;
        p0 = (_MP_Chunk*) ((char*) p0 + p0->alloc_mem);
    }

    *(_MP_Chunk**) ((char*) p1 + p1->alloc_mem - MP_CHUNKEND) = p1;
#ifdef _Z_MEMORYPOOL_THREAD_
    MP_UNLOCK(mp);
#endif
    return 0;
}
@userpro
Copy link
Owner

userpro commented Oct 12, 2024

只是确保前面是个合法的chunk(chunk header、chunk end都存在),不过确实可有可无肯定都是合法的chunk,先留着了

@userpro userpro self-assigned this Oct 12, 2024
@userpro userpro added the wontfix This will not be worked on label Oct 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants