bug-hurd
[Top][All Lists]
Advanced

[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 22:51:03 +0200
User-agent: NeoMutt/20170609 (1.8.3)

Andrew Eggenberger, le jeu. 22 avril 2021 20:37:02 -0500, a ecrit:
> But when I try to do the same in my translator, I get a "free(): invalid
> pointer"
> error. Here is the relevant portion of my code.
> 
>       filebuf = malloc(s.st_size + 1);
>       err = io_read(innerdir, &filebuf, &amt_written, 0, s.st_size);
>       free(filebuf);

Note that the RPC may replace filebuf with its own vm_allocate()-ed
buffer. The guide should not be documenting the use of malloc(), that's
confusing. Either the program has an already-allocated buffer to put the
data directly in, that it won't actually want to free. Or it wants to
allocate dynamically, and it's simpler to just make it NULL so the RPC
does the allocation. Possibly on successive RPC calls it's useful to
reuse an allocation, and eventually use vm_deallocate(), but surely not
free().

Samuel



reply via email to

[Prev in Thread] Current Thread [Next in Thread]