Re: [sqlite] Fwd: Possible small memory leak

2011-06-07 Thread Nico Williams
On Tue, Jun 7, 2011 at 5:31 AM, Ronald Burgman
 wrote:
> Now, I'm not sure if getpwuid actually allocates memory. Some
> documentation does not mention anything about it; some mention it is not
> possible; some mention that getpwuid can result in an ENOMEM
> (allocation failed) error,
> which clearly indicates that getpwuid tries to allocate some memory.
> Since I'm not sure I thought I should ask the experts.

getpwuid() and friends do NOT return allocated memory, ever.  They
*may* allocate memory for internal purposes while computing their
results, which is why they may return ENOMEM.  There is no memory leak
here.

Nico
--
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Fwd: Possible small memory leak

2011-06-07 Thread Alessandro Marzocchi
> Now, I'm not sure if getpwuid actually allocates memory. Some
> documentation does not mention anything about it; some mention it is not
> possible; some mention that getpwuid can result in an ENOMEM
> (allocation failed) error,
> which clearly indicates that getpwuid tries to allocate some memory.
> Since I'm not sure I thought I should ask the experts.

Hi, reading in getpwuid man page (IEEE Std 1003.1-2008)

"The return value may point to a static area which is overwritten by a
subsequent call to getpwent(), getpwnam(), or getpwuid()."

I think that any real implementation of this function will use a
static area, or otherwise will use a dynamically allocated one but
managed by the library itself. So i belive no free is necessary (and
anyways i can't put a free knowing that the returned pointer may be to
a static area). Regards
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Fwd: Possible small memory leak

2011-06-07 Thread Stephan Beal
On Tue, Jun 7, 2011 at 12:31 PM, Ronald Burgman <
r.w.burg...@student.utwente.nl> wrote:

> Now, I'm not sure if getpwuid actually allocates memory. Some
> documentation does not mention anything about it; some mention it is not
> possible; some mention that getpwuid can result in an ENOMEM
> (allocation failed) error,
> which clearly indicates that getpwuid tries to allocate some memory.
> Since I'm not sure I thought I should ask the experts.
>

According to the linux docs:


  The  return value may point to a static area, and may be overwritten
by
   subsequent calls to getpwent(3), getpwnam(), or  getpwuid().   (Do
 not
   pass the returned pointer to free(3).)

CONFORMING TO
   SVr4, 4.3BSD, POSIX.1-2001.


Since they do not list the do-not-free() as being incompatible with the
listed specifications, my strong instinct is to trust this description. The
linux man pages tend to explicitly mark any behaviours which do not conform
to the spec(s) mentioned in the "CONFORMING TO" section of the given man
page.

-- 
- stephan beal
http://wanderinghorse.net/home/stephan/
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


[sqlite] Fwd: Possible small memory leak

2011-06-07 Thread Ronald Burgman
Hej,

I was wondering about the following piece of code. It is part of the
find_home_dir procedure in shell.c.

2506: #if !defined(_WIN32) && !defined(WIN32) && !defined(__OS2__) &&
!defined(_WIN32_WCE) && !defined(__RTP__) && !defined(_WRS_KERNEL)
               struct passwd *pwent;
               uid_t uid = getuid();
               if( (pwent=getpwuid(uid)) != NULL) {
                       home_dir = pwent->pw_dir;
               }
2512: #endif

I think that pwent might be assigned with some allocated memory by the
call of getpwuid. If that is the case pwent is never freed and there
is a small memroy leak (I don't think this procedure is called that
often).

Now, I'm not sure if getpwuid actually allocates memory. Some
documentation does not mention anything about it; some mention it is not
possible; some mention that getpwuid can result in an ENOMEM
(allocation failed) error,
which clearly indicates that getpwuid tries to allocate some memory.
Since I'm not sure I thought I should ask the experts.

Cheers,
Ronald
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users