From: Jay Foster <jay@systech.com>
To: 'John Paul King' <jpking@advantexmail.net>,
ecos-discuss@sources.redhat.com
Subject: RE: [ECOS] Termios memory leak?
Date: Mon, 18 Jul 2005 16:37:00 -0000 [thread overview]
Message-ID: <80B97DE95AEED311BA580050047FE98403259494@mail.systech.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 2269 bytes --]
I ran into the same problem some time ago, and made the following change to
correct it. The bug would leak 8KB of memory each time cyg_io_lookup() was
called for a termios device (after the first time).
Index: ecos/packages/io/serial/current/src/common/termiostty.c
===================================================================
RCS file:
/cvs/ecos/ecos/packages/io/serial/current/src/common/termiostty.c,v
retrieving revision 1.6
diff -u -5 -p -r1.6 termiostty.c
--- ecos/packages/io/serial/current/src/common/termiostty.c 5 Sep 2003
05:09:19 -0000 1.6
+++ ecos/packages/io/serial/current/src/common/termiostty.c 18 Jul 2005
16:31:37 -0000
@@ -254,11 +254,12 @@ real_termios_init( struct termios_privat
res = cyg_io_get_config( priv->dev_handle,
CYG_IO_GET_CONFIG_SERIAL_BUFFER_INFO,
&dev_buf_conf, &len );
}
- priv->errbuf = (cyg_uint8 *)malloc( dev_buf_conf.rx_bufsize );
+ if ( NULL == priv->errbuf ) // Re-entrant code -- only do this once!
+ priv->errbuf = (cyg_uint8 *)malloc( dev_buf_conf.rx_bufsize );
if ( NULL == priv->errbuf )
res = ENOMEM; // FIXME: Are we allowed to do this?
priv->errbufpos = priv->errbuf;
priv->errbufsize = dev_buf_conf.rx_bufsize;
Jay
-----Original Message-----
From: John Paul King [mailto:jpking@advantexmail.net]
Sent: Sunday, July 17, 2005 2:28 PM
To: ecos-discuss@sources.redhat.com
Subject: [ECOS] Termios memory leak?
I've been using eCos w/ termios serial ports, and it seems that each
open/close of such devices allocates memory that is never freed. Struct
termios_private_info has a member 'errbuf' that is malloc'd in function
'real_termios_init' (packages/io/serial/src/common/termiostty.c), but I
never see a corrseponding 'free'. I grep'd through the source, and I
haven't seen any actions taken on 'errbuf' (other than allocation within
termiostty), so is it even used in eCos? I have temporarily removed the
few lines that deal w/ 'errbuf', and my application seems to work
properly now, but is this a safe thing to do?
--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss
[-- Attachment #2: termio.pat --]
[-- Type: application/octet-stream, Size: 1117 bytes --]
Index: ecos/packages/io/serial/current/src/common/termiostty.c
===================================================================
RCS file: /cvs/ecos/ecos/packages/io/serial/current/src/common/termiostty.c,v
retrieving revision 1.6
diff -u -5 -p -r1.6 termiostty.c
--- ecos/packages/io/serial/current/src/common/termiostty.c 5 Sep 2003 05:09:19 -0000 1.6
+++ ecos/packages/io/serial/current/src/common/termiostty.c 18 Jul 2005 16:31:37 -0000
@@ -254,11 +254,12 @@ real_termios_init( struct termios_privat
res = cyg_io_get_config( priv->dev_handle,
CYG_IO_GET_CONFIG_SERIAL_BUFFER_INFO,
&dev_buf_conf, &len );
}
- priv->errbuf = (cyg_uint8 *)malloc( dev_buf_conf.rx_bufsize );
+ if ( NULL == priv->errbuf ) // Re-entrant code -- only do this once!
+ priv->errbuf = (cyg_uint8 *)malloc( dev_buf_conf.rx_bufsize );
if ( NULL == priv->errbuf )
res = ENOMEM; // FIXME: Are we allowed to do this?
priv->errbufpos = priv->errbuf;
priv->errbufsize = dev_buf_conf.rx_bufsize;
[-- Attachment #3: Type: text/plain, Size: 148 bytes --]
--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss
next reply other threads:[~2005-07-18 16:37 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-07-18 16:37 Jay Foster [this message]
2005-07-21 18:02 ` Andrew Lunn
2005-07-26 17:25 ` Jonathan Larmour
-- strict thread matches above, loose matches on Subject: below --
2005-07-17 21:34 John Paul King
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=80B97DE95AEED311BA580050047FE98403259494@mail.systech.com \
--to=jay@systech.com \
--cc=ecos-discuss@sources.redhat.com \
--cc=jpking@advantexmail.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).