|
From: Xiang Y. <xy...@pr...> - 2003-04-10 17:40:36
|
Hello,
I got following message with --leak-check=3Dyes, valgrind 1.0.4.
=3D=3D1750=3D=3D 1825 bytes in 146 blocks are definitely lost in loss =
record 98 o
=3D=3D1750=3D=3D at 0x400485EC: __builtin_vec_new =
(vg_clientfuncs.c:156)
=3D=3D1750=3D=3D by 0x8061119: idgapis::prepareparams(void) =
(idgapis.cpp:904)
=3D=3D1750=3D=3D by 0x806199E: idgapis::proc(void) (idgapis.cpp:1052)
=3D=3D1750=3D=3D by 0x8063ED7: idgsockthread::callapi(void) =
(idgsockthread.cpp
My question is, for code below, valgrind will report an error or not on =
memory allocated for c1::m_p1?
class c1
{
~c1()=20
{
delete []m_p1;
}
void * m_p1;
}
class c2
{
~c2() {
if(m_c1 !=3D NULL)
delete []m_c1;
}
func1() {
m_c1 =3D new c1[10];
for(i =3D 0; i < 10; i++) {
m_c1[i].m_p1 =3D new char[10];
}
}=20
c1 *m_c1;
}
somewhere else outside above class has following call:
c2 *pc2 =3D new c2();
c2->func1();
delete c2;
TIA
Xiang
|
|
From: Nicholas N. <nj...@ca...> - 2003-04-10 18:33:28
|
On Thu, 10 Apr 2003, Xiang Yan wrote:
> My question is, for code below, valgrind will report an error or not on memory allocated for c1::m_p1?
> class c1
> {
> ~c1()
> {
> delete []m_p1;
> }
> void * m_p1;
> }
>
> class c2
> {
> ~c2() {
> if(m_c1 != NULL)
> delete []m_c1;
> }
> func1() {
> m_c1 = new c1[10];
> for(i = 0; i < 10; i++) {
> m_c1[i].m_p1 = new char[10];
> }
> }
> c1 *m_c1;
> }
>
> somewhere else outside above class has following call:
> c2 *pc2 = new c2();
> c2->func1();
> delete c2;
You've written an almost-whole program, and you want to know what Valgrind
says about it?
It looks to me like there won't be any errors, because AFAICT the memory
is all deallocated correctly. But I suggest you finish and compile the
program, and run Valgrind on it.
N
|
|
From: Xiang Y. <xy...@pr...> - 2003-04-10 20:29:12
|
On Thu, 10 Apr 2003, Xiang Yan wrote:
>
> > My question is, for code below, valgrind will report an error or not on
memory allocated for c1::m_p1?
> > class c1
> > {
> > ~c1()
> > {
> > delete []m_p1;
> > }
> > void * m_p1;
> > }
> >
> > class c2
> > {
> > ~c2() {
> > if(m_c1 != NULL)
> > delete []m_c1;
> > }
> > func1() {
> > m_c1 = new c1[10];
> > for(i = 0; i < 10; i++) {
> > m_c1[i].m_p1 = new char[10]; // reports definitely lost here
> > }
> > }
> > c1 *m_c1;
> > }
> >
> > somewhere else outside above class has following call:
> > c2 *pc2 = new c2();
> > c2->func1();
> > delete c2;
>
> You've written an almost-whole program, and you want to know what Valgrind
> says about it?
>
> It looks to me like there won't be any errors, because AFAICT the memory
> is all deallocated correctly. But I suggest you finish and compile the
> program, and run Valgrind on it.
That's the result of running Valgrind on my code, the line it indicated is
below with definitly lost message:
m_c1[i].m_p1 = new char[10]; // refer to above
(it's multithreaded btw)
|
|
From: Crispin F. <cr...@th...> - 2003-04-10 20:44:14
|
I just tried the sample code (once I had got it to compile) and it
worked fine - as expected. If you can provide a complete program that
acts as a test case, then you may have more luck tracking down the
problem in your code.
Crispin
On Thu, 2003-04-10 at 21:28, Xiang Yan wrote:
> On Thu, 10 Apr 2003, Xiang Yan wrote:
> >
> > > My question is, for code below, valgrind will report an error or not on
> memory allocated for c1::m_p1?
> > > class c1
> > > {
> > > ~c1()
> > > {
> > > delete []m_p1;
> > > }
> > > void * m_p1;
> > > }
> > >
> > > class c2
> > > {
> > > ~c2() {
> > > if(m_c1 != NULL)
> > > delete []m_c1;
> > > }
> > > func1() {
> > > m_c1 = new c1[10];
> > > for(i = 0; i < 10; i++) {
> > > m_c1[i].m_p1 = new char[10]; // reports definitely lost here
> > > }
> > > }
> > > c1 *m_c1;
> > > }
> > >
> > > somewhere else outside above class has following call:
> > > c2 *pc2 = new c2();
> > > c2->func1();
> > > delete c2;
> >
> > You've written an almost-whole program, and you want to know what Valgrind
> > says about it?
> >
> > It looks to me like there won't be any errors, because AFAICT the memory
> > is all deallocated correctly. But I suggest you finish and compile the
> > program, and run Valgrind on it.
>
> That's the result of running Valgrind on my code, the line it indicated is
> below with definitly lost message:
> m_c1[i].m_p1 = new char[10]; // refer to above
> (it's multithreaded btw)
>
>
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: Etnus, makers of TotalView, The debugger
> for complex code. Debugging C/C++ programs can leave you feeling lost and
> disoriented. TotalView can help you find your way. Available on major UNIX
> and Linux platforms. Try it free. www.etnus.com
> _______________________________________________
> Valgrind-users mailing list
> Val...@li...
> https://lists.sourceforge.net/lists/listinfo/valgrind-users
>
|