public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
From: Jonathan Larmour <jifl@eCosCentric.com>
To: Guenter Ebermann <guenter.ebermann@gmx.at>
Cc: ecos-discuss@ecos.sourceware.org
Subject: Re: [ECOS] Mixed use of delete with malloc in fclose
Date: Mon, 14 Jul 2008 11:29:00 -0000	[thread overview]
Message-ID: <487B388D.4010507@eCosCentric.com> (raw)
In-Reply-To: <20080627085844.163860@gmx.net>

Guenter Ebermann wrote:
> Hi All,
> 
> During searching a bug in our firmware (which was not related to ecos)
> I stumbled accross this minor inconsitency (which does not have an effect
> in our setup because the operator delete in libsupc++ of our gcc uses
> free internally):
> 
> In packages/language/c/libc/stdio/current/src/common/fopen.cxx
> line 172 (in Revision 1.9 - HEAD) memory is alloced with malloc and object is
> constructed with placement new:
> 
>     // Allocate it some memory and construct it.
>     curr_stream = (Cyg_StdioStream *)malloc(sizeof(*curr_stream));
>     if (curr_stream == NULL) {
>         cyg_stdio_close( dev );
>         Cyg_libc_stdio_files::unlock();
>         errno = ENOMEM;
>         return NULL;
>     } // if
> 
>     curr_stream = new ((void *)curr_stream) Cyg_StdioStream( dev, open_mode,
>                                                              append, binary,
>                                                              bufmode, bufsize );
> 
> But fclose frees memory useing delete (if it not overwritten with empty stubs).
> Please not that the (void *) cast at the new statement is also useless.
> For a proposed patch please see the attachment.

I'm not sure I understand the issue. If CYGFUN_INFRA_EMPTY_DELETE_FUNCTIONS
is not defined, then the implementation of delete in libsupc++ should call
free, just like you say is relevant for your setup.

The fact the constructor was called by placement new should be irrelevant.

Although I guess you could say the call to delete is redundant - you could
always run the code in the CYGFUN_INFRA_EMPTY_DELETE_FUNCTIONS block safely.

So just so I'm sure I understand it, this patch is not fixing a problem,
it's just a bit of cleanup, right?

When you reply you can provide a ChangeLog entry, thanks :-).

Jifl
-- 
eCosCentric Limited      http://www.eCosCentric.com/     The eCos experts
Barnwell House, Barnwell Drive, Cambridge, UK.       Tel: +44 1223 245571
Registered in England and Wales: Reg No 4422071.
------["Si fractum non sit, noli id reficere"]------       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

  reply	other threads:[~2008-07-14 11:29 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-27  9:02 Guenter Ebermann
2008-07-14 11:29 ` Jonathan Larmour [this message]
2008-07-20  0:20   ` Guenter Ebermann

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=487B388D.4010507@eCosCentric.com \
    --to=jifl@ecoscentric.com \
    --cc=ecos-discuss@ecos.sourceware.org \
    --cc=guenter.ebermann@gmx.at \
    /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).