Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #6919

Re: HEAP error when trying to use free() help needed

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news.mixmin.net!news.musoftware.de!wum.musoftware.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From Ian Collins <ian-news@hotmail.com>
Newsgroups comp.lang.c++
Subject Re: HEAP error when trying to use free() help needed
Date Mon, 20 Jun 2011 17:17:13 +1200
Lines 56
Message-ID <9683f5FsmeU3@mid.individual.net> (permalink)
References <75366d67-4c83-46cf-a75b-6a953578b6f8@v12g2000vby.googlegroups.com> <445a602a-ca39-4806-88bf-be5820678d7f@gv8g2000vbb.googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Trace individual.net 5gpGCx5DMn115jMggT1f+AMTxsIFA8kXZv40JOf83Dz0k20N3L
Cancel-Lock sha1:v2fU9XSeheRYJb+fNkEhMInhiV8=
User-Agent Mozilla/5.0 (X11; U; SunOS i86pc; en-US; rv:1.9.2.9) Gecko/20101021 Lightning/1.0b2 Thunderbird/3.1.4
In-Reply-To <445a602a-ca39-4806-88bf-be5820678d7f@gv8g2000vbb.googlegroups.com>
Xref x330-a1.tempe.blueboxinc.net comp.lang.c++:6919

Show key headers only | View raw


On 06/20/11 05:06 PM, none wrote:
> Thanks, everyone... sorry it took so long to reply...
>
> Here's the code I came up with:
>
>      class test {
>      public:
>
>
>          test (void) {
>              pPointer = (char *) malloc (sizeof(char));

Two things:

why are you using malloc?

sizeof(char) is one by definition.

>          }
>
>          // Copy constructor
>          test (const test&  mytest) {
>
>               pPointer = (char *) malloc (sizeof(char));
>              *pPointer = *mytest.pPointer;
>
>          }
>
>          ~test () {
>              free (pPointer);
>          }
>
>          test foo (void) {
>              test myfoo;
>              return myfoo;
>          }
>
>          // = operator overload
>          test&  operator= (const test&  mytest) {
>
>              *pPointer = *mytest.pPointer;
>
>              return *this;
>
>          }
>
>          char* pPointer;
>      };
>
> Is it correct? (if we suppose that for the purpose of this test
> pPointer will only point to a single char)

Well it won't leak or double free, but what do you really want to do?

-- 
Ian Collins

Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

HEAP error when trying to use free() help needed none <none9823@hotmail.com> - 2011-06-07 03:16 -0700
  Re: HEAP error when trying to use free() help needed "Fred Zwarts \(KVI\)" <F.Zwarts@KVI.nl> - 2011-06-07 13:11 +0200
  Re: HEAP error when trying to use free() help needed "Balog Pal" <pasa@lib.hu> - 2011-06-07 15:18 +0200
  Re: HEAP error when trying to use free() help needed "io_x" <a@b.c.invalid> - 2011-06-07 19:50 +0200
    Re: HEAP error when trying to use free() help needed "io_x" <a@b.c.invalid> - 2011-06-09 08:48 +0200
  Re: HEAP error when trying to use free() help needed "io_x" <a@b.c.invalid> - 2011-06-08 11:11 +0200
    Re: HEAP error when trying to use free() help needed Juha Nieminen <nospam@thanks.invalid> - 2011-06-08 10:17 +0000
  Re: HEAP error when trying to use free() help needed Mustansir <mustansir.azhar@gmail.com> - 2011-06-08 06:23 -0700
  Re: HEAP error when trying to use free() help needed Krice <paulkp@mbnet.fi> - 2011-06-08 11:42 -0700
    Re: HEAP error when trying to use free() help needed Pete Becker <pete@versatilecoding.com> - 2011-06-08 08:54 -1000
  Re: HEAP error when trying to use free() help needed none <none9823@hotmail.com> - 2011-06-19 22:06 -0700
    Re: HEAP error when trying to use free() help needed Ian Collins <ian-news@hotmail.com> - 2011-06-20 17:17 +1200
      Re: HEAP error when trying to use free() help needed none <none9823@hotmail.com> - 2011-06-19 22:53 -0700
        Re: HEAP error when trying to use free() help needed Juha Nieminen <nospam@thanks.invalid> - 2011-06-20 06:06 +0000
          Re: HEAP error when trying to use free() help needed none <none9823@hotmail.com> - 2011-06-20 00:35 -0700
            Re: HEAP error when trying to use free() help needed Ian Collins <ian-news@hotmail.com> - 2011-06-20 20:57 +1200
            Re: HEAP error when trying to use free() help needed Juha Nieminen <nospam@thanks.invalid> - 2011-06-20 18:25 +0000

csiph-web