jdah / jdh-8

An 8-bit minicomputer with a fully custom architecture
MIT License
1.29k stars 89 forks source link

Possible memory leak #18

Closed Kylogias closed 2 years ago

Kylogias commented 3 years ago

There is a possible memory leak in the load function of emu/libemu.c where the file may be bigger than 32K (the size of ROM) or even 64K (the size of the entire memory). This can leave to corrupted data when, for example, the screen is reading from memory, or another process modifies memory, or even the PROGRAM ITSELF modifies memory as it'll have an unknown size when assembled, thus you may read into/from memory that has program code

emneo-dev commented 2 years ago

I just looked at the code and it looks like it doesn't. emu_memcpy is protected against writing out of memory by the ppeek function in common/jdh8.h where this lines appears :

    if (addr >= ADDR_MB) {
        return &((u8 *) state->special.raw)[addr - ADDR_MB];

Here I think the only thing that could happen is that the memory would be overwritten.

jdah commented 2 years ago

Not a memory leak, but this should warn. Fixed in b5f7827e6181a5b37533012aad7acfc7881f4707, thanks!