This is the mail archive of the
ecos-discuss@sources.redhat.com
mailing list for the eCos project.
Bug in getifaddrs() - allocation of buffer
- From: Jay Foster <jay dot foster at systech dot com>
- To: "'ecos-discuss at sources dot redhat dot com'" <ecos-discuss at sources dot redhat dot com>
- Cc: Jay Foster <jay dot foster at systech dot com>
- Date: Tue, 16 Sep 2003 08:18:11 -0700
- Subject: [ECOS] Bug in getifaddrs() - allocation of buffer
The function getifaddrs() in file packages/net/common/current/src/ifaddrs.c
has a couple of bugs in it.
On lines 151 and 157, it calls "free(buf)", but "buf" is a local buffer
allocated on the stack. These should either be removed, or change the
allocation of "buf" to be malloced. These free() calls seem to indicate
that at one time, the "buf" buffer was malloced, which makes sense, since
it is a 1K byte buffer. This seems a bit large for an auto stack variable.
On lines 172 through 177 (CYGPKG_NET_INET6), it returns from the function
(error case), but does not free the malloced buffer "data". Need to add
a call to "free(data);" here. Also, if the "buf" buffer allocation is
changed to be malloced, instead of on the stack, then add a "free(buf);"
here too.
I will submit a patch, but I wanted to get some feedback/discussion about
the allocation of the "buf" buffer (malloced vs. on the stack).
Jay
--
Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss