public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
* [ECOS] Termios memory leak?
@ 2005-07-17 21:34 John Paul King
  0 siblings, 0 replies; 4+ messages in thread
From: John Paul King @ 2005-07-17 21:34 UTC (permalink / raw)
  To: ecos-discuss

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [ECOS] Termios memory leak?
  2005-07-21 18:02 ` Andrew Lunn
@ 2005-07-26 17:25   ` Jonathan Larmour
  0 siblings, 0 replies; 4+ messages in thread
From: Jonathan Larmour @ 2005-07-26 17:25 UTC (permalink / raw)
  To: Andrew Lunn; +Cc: ecos-discuss

Andrew Lunn wrote:
> On Mon, Jul 18, 2005 at 09:29:25AM -0700, Jay Foster wrote:
> 
>>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).
> 
> 
> Here is what i have committed. I removed the members from the priv
> structure as well just to tidy things up.

FAOD that's bound to have been the right thing to do. I suspect errbuf was 
just cruft from the initial implementation that was never deleted. I can't 
think now what it could have been intended for.

Jifl
-- 
eCosCentric    http://www.eCosCentric.com/    The eCos and RedBoot experts
--["No sense being pessimistic, it wouldn't work anyway"]-- Opinions==mine

-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [ECOS] Termios memory leak?
  2005-07-18 16:37 Jay Foster
@ 2005-07-21 18:02 ` Andrew Lunn
  2005-07-26 17:25   ` Jonathan Larmour
  0 siblings, 1 reply; 4+ messages in thread
From: Andrew Lunn @ 2005-07-21 18:02 UTC (permalink / raw)
  To: Jay Foster; +Cc: 'John Paul King', ecos-discuss

[-- Attachment #1: Type: text/plain, Size: 396 bytes --]

On Mon, Jul 18, 2005 at 09:29:25AM -0700, Jay Foster wrote:
> 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).

Here is what i have committed. I removed the members from the priv
structure as well just to tidy things up.

        Andrew

[-- Attachment #2: termiotty.diff --]
[-- Type: text/plain, Size: 1595 bytes --]

? termiotty.diff
Index: ChangeLog
===================================================================
RCS file: /cvs/ecos/ecos/packages/io/serial/current/ChangeLog,v
retrieving revision 1.63
diff -u -r1.63 ChangeLog
--- ChangeLog	28 Jun 2005 17:56:12 -0000	1.63
+++ ChangeLog	21 Jul 2005 18:00:33 -0000
@@ -1,3 +1,8 @@
+2005-07-21  Andrew Lunn  <andrew.lunn@ascom.ch>
+
+	* src/common/termiostty.c: Removed errbuf from priv. It was never
+	being used after being allocated and never freed.
+
 2005-06-27  Andrew Lunn <andrew.lunn@ascom.ch>
 
 	* src/common/serial.c (serial_select): Swap the DSR locks and
Index: src/common/termiostty.c
===================================================================
RCS file: /cvs/ecos/ecos/packages/io/serial/current/src/common/termiostty.c,v
retrieving revision 1.6
diff -u -r1.6 termiostty.c
--- src/common/termiostty.c	5 Sep 2003 05:09:19 -0000	1.6
+++ src/common/termiostty.c	21 Jul 2005 18:00:34 -0000
@@ -107,9 +107,6 @@
     cyg_io_handle_t dev_handle;
     cyg_drv_mutex_t lock;
     cyg_bool        init;
-    cyg_uint8      *errbuf;
-    cyg_uint8      *errbufpos;
-    cyg_uint32      errbufsize;
 };
 
 typedef struct {
@@ -256,12 +253,6 @@
                                  &dev_buf_conf, &len );
     }
 
-    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;
-
     if ( ENOERR != res ) {
         CYG_REPORT_RETVAL( res );
         return res;


[-- 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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: [ECOS] Termios memory leak?
@ 2005-07-18 16:37 Jay Foster
  2005-07-21 18:02 ` Andrew Lunn
  0 siblings, 1 reply; 4+ messages in thread
From: Jay Foster @ 2005-07-18 16:37 UTC (permalink / raw)
  To: 'John Paul King', ecos-discuss

[-- 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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2005-07-26 17:25 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-07-17 21:34 [ECOS] Termios memory leak? John Paul King
2005-07-18 16:37 Jay Foster
2005-07-21 18:02 ` Andrew Lunn
2005-07-26 17:25   ` Jonathan Larmour

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).