Re: [PATCH] strbuf: release memory on read error in strbuf_read_once()

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

 



On Thu, Dec 07, 2017 at 09:51:26PM +0100, René Scharfe wrote:

> If other strbuf add functions cause the first allocation and
> subsequently encounter an error then they release the memory, restoring
> the pristine state of the strbuf.  That simplifies error handling for
> callers.
> 
> Do the same in strbuf_read_once(), and do it also in case no bytes were
> read -- which may or may not be an error as well, depending on the
> caller.

Makes sense, and the patch is delightfully simple.

For the "0" case nobody should be negatively impacted by dropping the
allocation, as they get a sane 0-length string from the slopbuf (and
anybody who relies on sb->buf being allocated without calling detach or
similar is already doing it wrong).

-Peff



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux