Re: Handling ioctl() argp memory

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



leslie.polzer@xxxxxxx wrote:

> > You're probably overwriting the beginning of the allocated block.
> 
> What do you mean by that?  I can surely write to allocated memory, at
> the start, end and any point between...

Each block returned from malloc etc has a header; the pointer which
malloc() returns points to the first byte after the header. If you
corrupt the header, you will often get a segfault when you try to
free() the block.

> Besides, for the record: a short Valgrind run (thanks for the reminder!)
> showed me that I calculated the space wrongly, i.e. I allocated not
> enough memory.

If you write beyond the end of one block, you'll often end up
corrupting the header at the beginning of the block which follows it
in memory.

Not always, as there may be some unused space after the end of the
block; it's more likely to happen with simple programs where the
blocks are likely to be adjacent in memory.

-- 
Glynn Clements <glynn@xxxxxxxxxxxxxxxxxx>
-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Assembler]     [Git]     [Kernel List]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [C Programming]     [Yosemite Campsites]     [Yosemite News]     [GCC Help]

  Powered by Linux