[PATCH v2 1/2] [libXau] XauGetFileName: added a thread-safe variant of XauFileName

2011-03-30 Thread Erkki Seppälä
XauGetFileName has argument char **buffer, which can be used to provide an existing buffer for XauGetFileName to store the result in. *buffer can be NULL, in which case a newly allocated block of memory will be allocated and stored at *buffer. The function also provides means to signal the required

Re: [PATCH v2 1/2] [libXau] XauGetFileName: added a thread-safe variant of XauFileName

2011-03-31 Thread Mark Marshall
On 30/03/2011 09:53, Erkki Seppälä wrote: +static const char * +xau_getenv(const char *name) +{ +size_t len= 64; +char *buffer = malloc (len); +intrc = 0; + +while (buffer + && (rc = getenv_r (name, buffer, len)) == -1 + && errno == ERANGE) { +

Re: [PATCH v2 1/2] [libXau] XauGetFileName: added a thread-safe variant of XauFileName

2011-03-31 Thread Mikhail Gusarov
Twas brillig at 13:13:23 31.03.2011 UTC+01 when mark.marsh...@csr.com did gyre and gimble: >> +static const char * >> +xau_getenv(const char *name) >> +{ >> +size_t len= 64; >> +char *buffer = malloc (len); >> +intrc = 0; >> + >> +while (buffer >> +

Re: [PATCH v2 1/2] [libXau] XauGetFileName: added a thread-safe variant of XauFileName

2011-03-31 Thread Mark Kettenis
> From: Mikhail Gusarov > Date: Thu, 31 Mar 2011 14:18:13 +0200 > > Twas brillig at 13:13:23 31.03.2011 UTC+01 when mark.marsh...@csr.com > did gyre and gimble: > > >> +static const char * > >> +xau_getenv(const char *name) > >> +{ > >> +size_t len=3D 64; > >> +char *buff

Re: [PATCH v2 1/2] [libXau] XauGetFileName: added a thread-safe variant of XauFileName

2011-03-31 Thread Mark Kettenis
> From: =?UTF-8?q?Erkki=20Sepp=C3=A4l=C3=A4?= > Date: Wed, 30 Mar 2011 11:53:53 +0300 > > XauGetFileName has argument char **buffer, which can be used to > provide an existing buffer for XauGetFileName to store the result > in. *buffer can be NULL, in which case a newly allocated block of > memor

Re: [PATCH v2 1/2] [libXau] XauGetFileName: added a thread-safe variant of XauFileName

2011-03-31 Thread Erkki Seppala
On 31.03.2011 15:13, Mark Marshall wrote: There's a (very unlikely) memory leak here. (getenv_r() == -1 and errno != ERANGE) Thanks! Can't believe how I missed that. (Or how I missed it in my valgrind-based tests.) ___ xorg-devel@lists.x.org: X.Org

Re: [PATCH v2 1/2] [libXau] XauGetFileName: added a thread-safe variant of XauFileName

2011-03-31 Thread Erkki Seppala
On 31.03.2011 16:13, Mark Kettenis wrote: Sorry, but I think that is a bad API. It will lead to confusion who allocated the buffer. I would hope the documentation makes this clear. Unfortunately this is that kind of API where one wants to look at the documentation :). Also somebody noted t