[PATCH] kexec: use mmap instead of read for slurp_file()

Michael Holzheu holzheu at linux.vnet.ibm.com
Thu Oct 15 05:31:38 PDT 2015


On Wed, 14 Oct 2015 17:05:52 -0700
Geoff Levand <geoff at infradead.org> wrote:

[snip]

> >  		if (err < 0)
> >  > 	> 	> 	> die("Can not seek to the begin of file %s: %s\n",
> >  > 	> 	> 	> 	> 	> filename, strerror(errno));
> > +> 	> 	> buf = slurp_fd(fd, filename, size, &nread);
> >  > 	> } else {
> > -> 	> 	> size = stats.st_size;
> > +> 	> 	> size = nread = stats.st_size;
> > +> 	> 	> buf = mmap(NULL, size,
> 
> With this change the caller can't tell if buf was malloc'ed or mmaped.  The
> only safe thing it can do is to not call free() on the returned buf, this will
> lead to memory leakage for malloc'ed buffers.

I have read the code and have not found any free call. Therefore I assumed
that the kexec approach is to not free the buffer *explicitly* and leave to
the kernel to free it *automatically* at process exit.

@Simon: Was this assumption wrong?

Michael




More information about the kexec mailing list