On Fri, 31 Oct 2014, Peter Maydell wrote: > On 31 October 2014 10:42, Nikita Belov <zod...@ispras.ru> wrote: > > On 2014-10-29 19:03, Peter Maydell wrote: > >> We leak all of the MemoryRegions we allocate here, because we > >> don't have a persistent state struct to keep them in. This > >> doesn't really matter much because they're generally needed > >> for the lifetime of the QEMU process anyway, and we only call > >> board init functions once. So why worry about ram_lo in > >> particular (and why this board in particular)? > > > Indeed, generally we need memory regions for the lifetime of QEMU, but > > 'mem_lo' > > is different. It may not be used at all. We use 'ram_lo' only when a > > condition is > > true, in other case we will lose this pointer. Because of that if the > > condition is > > false we have memory leak immediately (not when QEMU exits). > > No, ram_lo is exactly the same as the other memory regions > here: we allocate it in this function, we don't keep any > kind of pointer to it after we leave this function,
This is not true. We keep pointer to the memory region when we add it as a subregion of another region. As long as we have a pointer to a root region(s) we have a pointer to any other used region. Which is not the case for unused ones. Actually it is impossible to use a dinamically allocated piece of memory and not to have a pointer to it at the same time. > and > we rely on it being freed on QEMU exit. The fact that we > don't happen to use ram_lo in all cases is irrelevant. > -- Kirill