[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Memory management for io_read(), etc.
From: |
Samuel Thibault |
Subject: |
Re: Memory management for io_read(), etc. |
Date: |
Sat, 24 Apr 2021 23:12:44 +0200 |
User-agent: |
NeoMutt/20170609 (1.8.3) |
Andrew Eggenberger, le sam. 24 avril 2021 16:06:25 -0500, a ecrit:
> Thanks Samuel. So if I'm understanding correctly, if I let the RPC vm_allocate
> () filebuf I don't need to worry about vm_deallocating it?
You have to vm_deallocate() it, otherwise it'll leak.
> And if I wanted to pass a buffer in and reuse it, I should use
> vm_allocate() instead of malloc()?
You can use malloc, you'll then have to use free on it *and*
vm_deallocate the value set by the RPC if it did change the pointer.
That's clearer to just use vm_deallocate in both case. See how it's done
in various codeplaces, you'll find tests such as if (buf != alloc_buf)
vm_deallocate(alloc_buf);
Samuel