From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29928 invoked by alias); 18 Jul 2005 16:37:04 -0000 Mailing-List: contact ecos-discuss-help@ecos.sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: ecos-discuss-owner@ecos.sourceware.org Received: (qmail 29761 invoked by uid 22791); 18 Jul 2005 16:36:48 -0000 Received: from [209.75.216.5] (HELO mail.systech.com) (209.75.216.5) by sourceware.org (qpsmtpd/0.30-dev) with ESMTP; Mon, 18 Jul 2005 16:36:48 +0000 Received: by mail.systech.com with Internet Mail Service (5.5.2650.21) id <3NN7GWCR>; Mon, 18 Jul 2005 09:29:27 -0700 Message-ID: <80B97DE95AEED311BA580050047FE98403259494@mail.systech.com> From: Jay Foster To: 'John Paul King' , ecos-discuss@sources.redhat.com Date: Mon, 18 Jul 2005 16:37:00 -0000 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----_=_NextPart_000_01C58BB5.DCEBCC50" Subject: RE: [ECOS] Termios memory leak? X-SW-Source: 2005-07/txt/msg00168.txt.bz2 ------_=_NextPart_000_01C58BB5.DCEBCC50 Content-Type: text/plain; charset="iso-8859-1" Content-length: 2269 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 ------_=_NextPart_000_01C58BB5.DCEBCC50 Content-Type: application/octet-stream; name="termio.pat" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="termio.pat" Content-length: 1355 Index: ecos/packages/io/serial/current/src/common/termiostty.c=0A= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A= RCS file: /cvs/ecos/ecos/packages/io/serial/current/src/common/termiostty.c= ,v=0A= retrieving revision 1.6=0A= diff -u -5 -p -r1.6 termiostty.c=0A= --- ecos/packages/io/serial/current/src/common/termiostty.c 5 Sep 2003 05:0= 9:19 -0000 1.6=0A= +++ ecos/packages/io/serial/current/src/common/termiostty.c 18 Jul 2005 16:= 31:37 -0000=0A= @@ -254,11 +254,12 @@ real_termios_init( struct termios_privat=0A= res =3D cyg_io_get_config( priv->dev_handle,=0A= CYG_IO_GET_CONFIG_SERIAL_BUFFER_INFO,=0A= &dev_buf_conf, &len );=0A= }=0A= =20=0A= - priv->errbuf =3D (cyg_uint8 *)malloc( dev_buf_conf.rx_bufsize );=0A= + if ( NULL =3D=3D priv->errbuf ) // Re-entrant code -- only do this on= ce!=0A= + priv->errbuf =3D (cyg_uint8 *)malloc( dev_buf_conf.rx_bufsize );= =0A= if ( NULL =3D=3D priv->errbuf )=0A= res =3D ENOMEM; // FIXME: Are we allowed to do this?=0A= priv->errbufpos =3D priv->errbuf;=0A= priv->errbufsize =3D dev_buf_conf.rx_bufsize;=0A= =20=0A= =0A= ------_=_NextPart_000_01C58BB5.DCEBCC50 Content-Type: text/plain; charset=us-ascii Content-length: 148 -- Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss ------_=_NextPart_000_01C58BB5.DCEBCC50--