Double Free on Writing to File
Hi
I have the following snippet of code which I'm trying to use to colour a mesh:
double inner_radius = 20;
double outer_radius = 35;
for (VertexIterator vertex(mesh); !vertex.end(); ++vertex) {
xy = new Array<double>(dim, geometry.
x0 = (*xy)[0]; x1 = (*xy)[1]; x2 = 0; //(*xy)[2];
if (sqrt(x0*x0 + x1*x1) < inner_radius + 0.3*(outer_
new cell_A;
else
new cell_B;
}
Vector temp(mesh.
double block[mesh.
// Indices of the row of the vector to set
for (unsigned int i = 0; i < mesh.num_
rows[i] = i;
// Output file in VTK format
File file("out.pvd");
int i = 0;
for (std::vector<
if((*p)->celltype == Cell_A) {
block[i] = 20;
}
else
block[i] = -86;
++i;
}
temp.set(block, mesh.num_
Function u(V, temp);
file << u;
plot(u);
I get the following error(s) when I run it [ There's no error if I remove file << u and plot(u) ]:
*** glibc detected *** ./colour_mesh: double free or corruption (out): 0x00000000128961e0 ***
======= Backtrace: =========
/lib/libc.
/lib/libc.
/home/pietro/
/home/pietro/
/home/pietro/
/home/pietro/
/home/pietro/
./colour_
/lib/libc.
./colour_
======= Memory map: ========
00400000-00438000 r-xp 00000000 08:01 16450481 /home/pietro/
00637000-00638000 r--p 00037000 08:01 16450481 /home/pietro/
00638000-00639000 rw-p 00038000 08:01 16450481 /home/pietro/
01975000-129bb000 rw-p 00000000 00:00 0 [heap]
7f7510000000-
7f7510021000-
7f75144cc000-
7f75144d8000-
7f75146d7000-
7f75146d8000-
7f75146d9000-
7f75146e3000-
7f75148e2000-
7f75148e3000-
7f75148e4000-
7f75148fc000-
7f7514afb000-
7f7514afc000-
7f7514afd000-
7f7514b00000-
7f7514cff000-
7f7514d00000-
7f7514f07000-
7f7514f09000-
7f7515108000-
7f7515109000-
7f751510a000-
7f751510d000-
7f751530c000-
7f751530d000-
7f751530e000-
7f7515312000-
7f7515512000-
7f7515513000-
7f7515514000-
7f751551c000-
7f751571b000-
7f751571c000-
7f751571d000-
7f7515728000-
7f7515927000-
7f7515928000-
7f7515929000-
7f75159a9000-
7f75159af000-
7f7515bae000-
7f7515baf000-
7f7515bb0000-
7f7515bb3000-
7f7515db2000-
7f7515db3000-
7f75163fc000-
7f7516400000-
7f75165ff000-
[wm:17807] Signal: Aborted (6)
[wm:17807] Signal code: (-6)
[wm:17807] [ 0] /lib/libpthread
[wm:17807] [ 1] /lib/libc.
[wm:17807] [ 2] /lib/libc.
[wm:17807] [ 3] /lib/libc.
[wm:17807] [ 4] /lib/libc.
[wm:17807] [ 5] /lib/libc.
[wm:17807] [ 6] /home/pietro/
[wm:17807] [ 7] /home/pietro/
[wm:17807] [ 8] /home/pietro/
[wm:17807] [ 9] /home/pietro/
[wm:17807] [10] /home/pietro/
[wm:17807] [11] ./colour_
[wm:17807] [12] /lib/libc.
[wm:17807] [13] ./colour_mesh() [0x40fd19]
[wm:17807] *** End of error message ***
===
It seems the error has to do with : file << u
How can I resolve this?
Thanks
Pietro
Question information
- Language:
- English Edit question
- Status:
- Solved
- For:
- DOLFIN Edit question
- Assignee:
- No assignee Edit question
- Solved by:
- Pietro Maximoff
- Solved:
- 2010-06-29
- Last query:
- 2010-06-29
- Last reply:
- 2010-06-29
Anders Logg (logg) said : | #1 |
Try to create a simpler example if you want us to debug.
To begin with, there seems to be a call to new in
xy = new Array<double>(dim, geometry.
which is never freed.
--
Anders
On Tue, Jun 29, 2010 at 02:53:57PM -0000, Pietro Maximoff wrote:
> New question #116136 on DOLFIN:
> https:/
>
> Hi
>
> I have the following snippet of code which I'm trying to use to colour a mesh:
>
> double inner_radius = 20;
> double outer_radius = 35;
>
> for (VertexIterator vertex(mesh); !vertex.end(); ++vertex) {
> xy = new Array<double>(dim, geometry.
> x0 = (*xy)[0]; x1 = (*xy)[1]; x2 = 0; //(*xy)[2];
>
> if (sqrt(x0*x0 + x1*x1) < inner_radius + 0.3*(outer_
> new cell_A;
> else
> new cell_B;
> }
>
> Vector temp(mesh.
> double block[mesh.
> dolfin::uint rows[mesh.
>
> // Indices of the row of the vector to set
> for (unsigned int i = 0; i < mesh.num_
> rows[i] = i;
>
> // Output file in VTK format
> File file("out.pvd");
>
>
> int i = 0;
> for (std::vector<
> if((*p)->celltype == Cell_A) {
> block[i] = 20;
> }
> else
> block[i] = -86;
>
> ++i;
> }
>
> temp.set(block, mesh.num_
> Function u(V, temp);
>
> file << u;
>
> plot(u);
>
> I get the following error(s) when I run it [ There's no error if I remove file << u and plot(u) ]:
>
> *** glibc detected *** ./colour_mesh: double free or corruption (out): 0x00000000128961e0 ***
> ======= Backtrace: =========
> /lib/libc.
> /lib/libc.
> /home/pietro/
> /home/pietro/
> /home/pietro/
> /home/pietro/
> /home/pietro/
> ./colour_
> /lib/libc.
> ./colour_
> ======= Memory map: ========
> 00400000-00438000 r-xp 00000000 08:01 16450481 /home/pietro/
> 00637000-00638000 r--p 00037000 08:01 16450481 /home/pietro/
> 00638000-00639000 rw-p 00038000 08:01 16450481 /home/pietro/
> 01975000-129bb000 rw-p 00000000 00:00 0 [heap]
> 7f7510000000-
> 7f7510021000-
> 7f75144cc000-
> 7f75144d8000-
> 7f75146d7000-
> 7f75146d8000-
> 7f75146d9000-
> 7f75146e3000-
> 7f75148e2000-
> 7f75148e3000-
> 7f75148e4000-
> 7f75148fc000-
> 7f7514afb000-
> 7f7514afc000-
> 7f7514afd000-
> 7f7514b00000-
> 7f7514cff000-
> 7f7514d00000-
> 7f7514f07000-
> 7f7514f09000-
> 7f7515108000-
> 7f7515109000-
> 7f751510a000-
> 7f751510d000-
> 7f751530c000-
> 7f751530d000-
> 7f751530e000-
> 7f7515312000-
> 7f7515512000-
> 7f7515513000-
> 7f7515514000-
> 7f751551c000-
> 7f751571b000-
> 7f751571c000-
> 7f751571d000-
> 7f7515728000-
> 7f7515927000-
> 7f7515928000-
> 7f7515929000-
> 7f75159a9000-
> 7f75159af000-
> 7f7515bae000-
> 7f7515baf000-
> 7f7515bb0000-
> 7f7515bb3000-
> 7f7515db2000-
> 7f7515db3000-
> 7f75163fc000-
> 7f7516400000-
> 7f75165ff000-
> [wm:17807] Signal: Aborted (6)
> [wm:17807] Signal code: (-6)
> [wm:17807] [ 0] /lib/libpthread
> [wm:17807] [ 1] /lib/libc.
> [wm:17807] [ 2] /lib/libc.
> [wm:17807] [ 3] /lib/libc.
> [wm:17807] [ 4] /lib/libc.
> [wm:17807] [ 5] /lib/libc.
> [wm:17807] [ 6] /home/pietro/
> [wm:17807] [ 7] /home/pietro/
> [wm:17807] [ 8] /home/pietro/
> [wm:17807] [ 9] /home/pietro/
> [wm:17807] [10] /home/pietro/
> [wm:17807] [11] ./colour_
> [wm:17807] [12] /lib/libc.
> [wm:17807] [13] ./colour_mesh() [0x40fd19]
> [wm:17807] *** End of error message ***
>
> ===
>
> It seems the error has to do with : file << u
>
> How can I resolve this?
>
> Thanks
>
> Pietro
>
>
>
Pietro Maximoff (segment-x) said : | #2 |
I assumed/assume the call to 'new' in
xy = new Array<double>(dim, geometry.
would be freed as the Array class has a destructor.
But the main problem seems to be writing to the output to VTK file
Also, if I create a MATLAB output file, instead of a VTK output file, it works fine, i.e.,
File file("out.m");
file << u.vector();
What I've essentially tried to do in the code is:
Load a 2D mesh (shape of a doughnut).
For every vertex in the mesh, if it's within a certain distance, the solution at that vertex is output as 20 otherwise as -86.
I've used a vector to gather the individual entries and then converted it to a function for output. Please let me know If there's a more efficient way.
Thanks.
Pietro
===========
Vector temp(mesh.
double block[mesh.
dolfin::uint rows[mesh.
int i = 0;
for (VertexIterator vertex(mesh); !vertex.end(); ++vertex) {
xy = new Array<double>(dim, geometry.
x0 = (*xy)[0];
x1 = (*xy)[1];
if (sqrt(x0*x0 + x1*x1) < 21.5)
block[i] = 20;;
else
block[i] = -86;
++i;
}
// Indices of the row of the vector to set --- ALL indices
for (unsigned int i = 0; i < mesh.num_
rows[i] = i;
// Output file in VTK format
File file("out.pvd");
temp.set(block, mesh.num_
Function u(V, temp);
file << u;
plot(u);
Anders Logg (logg) said : | #3 |
On Tue, Jun 29, 2010 at 04:34:04PM -0000, Pietro Maximoff wrote:
> Question #116136 on DOLFIN changed:
> https:/
>
> Status: Answered => Open
>
> Pietro Maximoff is still having a problem:
> I assumed/assume the call to 'new' in
> xy = new Array<double>(dim, geometry.
> would be freed as the Array class has a destructor.
No it won't since there's no object that goes out of scope and calls
the destructor.
> But the main problem seems to be writing to the output to VTK file
>
> *** glibc detected *** ./colour_mesh: double free or
> corruption (out):
>
> Also, if I create a MATLAB output file, instead of a VTK output file,
> it works fine, i.e.,
>
> File file("out.m");
> file << u.vector();
>
>
> What I've essentially tried to do in the code is:
>
> Load a 2D mesh (shape of a doughnut).
> For every vertex in the mesh, if it's within a certain distance, the solution at that vertex is output as 20 otherwise as -86.
>
> I've used a vector to gather the individual entries and then converted
> it to a function for output. Please let me know If there's a more
> efficient way.
Unfortunately I don't have time to think about what the best solution
to your problem is right now, but if you send me a stripped down and
simple test program that segfaults because of a bug in DOLFIN, I will
fix the bug.
--
Anders
Pietro Maximoff (segment-x) said : | #4 |
Hi
My sincere apologies. I just checked the UFL form. I forgot to change the element from tetrahedron to triangle.
That fixed the problem.
Thanks Anders.
Isn't it strange though, that I still got output in matlab format?
Pietro
Anders Logg (logg) said : | #5 |
On Tue, Jun 29, 2010 at 04:59:17PM -0000, Pietro Maximoff wrote:
> Question #116136 on DOLFIN changed:
> https:/
>
> Status: Answered => Solved
>
> Pietro Maximoff confirmed that the question is solved:
> Hi
>
> My sincere apologies. I just checked the UFL form. I forgot to change
> the element from tetrahedron to triangle.
>
> That fixed the problem.
>
> Thanks Anders.
>
> Isn't it strange though, that I still got output in matlab format?
>
> Pietro
It might do things in different ways.
--
Anders