← Back to team overview

dolfin team mailing list archive

[Question #116136]: Double Free on Writing to File

 

New question #116136 on DOLFIN:
https://answers.launchpad.net/dolfin/+question/116136

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.x(vertex->index()));
		x0 = (*xy)[0]; x1 = (*xy)[1]; x2 = 0; //(*xy)[2];
		
		if (sqrt(x0*x0 + x1*x1) < inner_radius + 0.3*(outer_radius-inner_radius))
			new cell_A;
		else
			new cell_B;
	}
	
	Vector temp(mesh.num_vertices());
	double block[mesh.num_vertices()];
        dolfin::uint rows[mesh.num_vertices()];
	
	// Indices of the row of the vector to set
	for (unsigned int i = 0; i < mesh.num_vertices(); ++i) 
            rows[i] = i;
	
	// Output file in VTK format
	File file("out.pvd");
	

	int i = 0;
	for (std::vector<Cells*>::iterator p = Cell::instances_.begin(); p != Cell::instances_.end(); ++p) {
		if((*p)->celltype == Cell_A) {
			block[i] = 20;
		}
		else 
			block[i] = -86;
			
		++i;
	} 
	
	temp.set(block, mesh.num_vertices(), rows);
	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.so.6(+0x775b6)[0x7f751b8f55b6]
/lib/libc.so.6(cfree+0x73)[0x7f751b8fbe53]
/home/pietro/FEniCS/lib/libdolfin.so.0(_ZN6dolfin7UFCCellD1Ev+0x51)[0x7f7523c6fdc1]
/home/pietro/FEniCS/lib/libdolfin.so.0(_ZNK6dolfin8Function21compute_vertex_valuesERNS_5ArrayIdEERKNS_4MeshE+0x6c8)[0x7f7523cb8d08]
/home/pietro/FEniCS/lib/libdolfin.so.0(_ZNK6dolfin7VTKFile16write_point_dataERKNS_15GenericFunctionERKNS_4MeshESs+0x123)[0x7f7523cd43d3]
/home/pietro/FEniCS/lib/libdolfin.so.0(_ZNK6dolfin7VTKFile13results_writeERKNS_8FunctionESs+0xdc)[0x7f7523cd594c]
/home/pietro/FEniCS/lib/libdolfin.so.0(_ZN6dolfin7VTKFilelsERKNS_8FunctionE+0x87)[0x7f7523cd7347]
./colour_mesh(main+0x805)[0x417fa5]
/lib/libc.so.6(__libc_start_main+0xfd)[0x7f751b89cc4d]
./colour_mesh[0x40fd19]
======= Memory map: ========
00400000-00438000 r-xp 00000000 08:01 16450481                           /home/pietro/workspace/colour_mesh
00637000-00638000 r--p 00037000 08:01 16450481                           /home/pietro/workspace/colour_mesh
00638000-00639000 rw-p 00038000 08:01 16450481                           /home/pietro/workspace/colour_mesh
01975000-129bb000 rw-p 00000000 00:00 0                                  [heap]
7f7510000000-7f7510021000 rw-p 00000000 00:00 0 
7f7510021000-7f7514000000 ---p 00000000 00:00 0 
7f75144cc000-7f75144d8000 r-xp 00000000 08:01 43846511                   /usr/local/lib/openmpi/mca_osc_rdma.so
7f75144d8000-7f75146d7000 ---p 0000c000 08:01 43846511                   /usr/local/lib/openmpi/mca_osc_rdma.so
7f75146d7000-7f75146d8000 r--p 0000b000 08:01 43846511                   /usr/local/lib/openmpi/mca_osc_rdma.so
7f75146d8000-7f75146d9000 rw-p 0000c000 08:01 43846511                   /usr/local/lib/openmpi/mca_osc_rdma.so
7f75146d9000-7f75146e3000 r-xp 00000000 08:01 43846509                   /usr/local/lib/openmpi/mca_osc_pt2pt.so
7f75146e3000-7f75148e2000 ---p 0000a000 08:01 43846509                   /usr/local/lib/openmpi/mca_osc_pt2pt.so
7f75148e2000-7f75148e3000 r--p 00009000 08:01 43846509                   /usr/local/lib/openmpi/mca_osc_pt2pt.so
7f75148e3000-7f75148e4000 rw-p 0000a000 08:01 43846509                   /usr/local/lib/openmpi/mca_osc_pt2pt.so
7f75148e4000-7f75148fc000 r-xp 00000000 08:01 43846497                   /usr/local/lib/openmpi/mca_coll_tuned.so
7f75148fc000-7f7514afb000 ---p 00018000 08:01 43846497                   /usr/local/lib/openmpi/mca_coll_tuned.so
7f7514afb000-7f7514afc000 r--p 00017000 08:01 43846497                   /usr/local/lib/openmpi/mca_coll_tuned.so
7f7514afc000-7f7514afd000 rw-p 00018000 08:01 43846497                   /usr/local/lib/openmpi/mca_coll_tuned.so
7f7514afd000-7f7514b00000 r-xp 00000000 08:01 43846495                   /usr/local/lib/openmpi/mca_coll_sync.so
7f7514b00000-7f7514cff000 ---p 00003000 08:01 43846495                   /usr/local/lib/openmpi/mca_coll_sync.so
7f7514cff000-7f7514d00000 r--p 00002000 08:01 43846495                   /usr/local/lib/openmpi/mca_coll_sync.so
7f7514d00000-7f7514d01000 rw-p 00003000 08:01 43846495                   /usr/local/lib/openmpi/mca_coll_sync.so
7f7514f07000-7f7514f09000 r-xp 00000000 08:01 43846491                   /usr/local/lib/openmpi/mca_coll_self.so
7f7514f09000-7f7515108000 ---p 00002000 08:01 43846491                   /usr/local/lib/openmpi/mca_coll_self.so
7f7515108000-7f7515109000 r--p 00001000 08:01 43846491                   /usr/local/lib/openmpi/mca_coll_self.so
7f7515109000-7f751510a000 rw-p 00002000 08:01 43846491                   /usr/local/lib/openmpi/mca_coll_self.so
7f751510a000-7f751510d000 r-xp 00000000 08:01 43846489                   /usr/local/lib/openmpi/mca_coll_inter.so
7f751510d000-7f751530c000 ---p 00003000 08:01 43846489                   /usr/local/lib/openmpi/mca_coll_inter.so
7f751530c000-7f751530d000 r--p 00002000 08:01 43846489                   /usr/local/lib/openmpi/mca_coll_inter.so
7f751530d000-7f751530e000 rw-p 00003000 08:01 43846489                   /usr/local/lib/openmpi/mca_coll_inter.so
7f751530e000-7f7515312000 r-xp 00000000 08:01 43846487                   /usr/local/lib/openmpi/mca_coll_hierarch.so
7f7515312000-7f7515512000 ---p 00004000 08:01 43846487                   /usr/local/lib/openmpi/mca_coll_hierarch.so
7f7515512000-7f7515513000 r--p 00004000 08:01 43846487                   /usr/local/lib/openmpi/mca_coll_hierarch.so
7f7515513000-7f7515514000 rw-p 00005000 08:01 43846487                   /usr/local/lib/openmpi/mca_coll_hierarch.so
7f7515514000-7f751551c000 r-xp 00000000 08:01 43846485                   /usr/local/lib/openmpi/mca_coll_basic.so
7f751551c000-7f751571b000 ---p 00008000 08:01 43846485                   /usr/local/lib/openmpi/mca_coll_basic.so
7f751571b000-7f751571c000 r--p 00007000 08:01 43846485                   /usr/local/lib/openmpi/mca_coll_basic.so
7f751571c000-7f751571d000 rw-p 00008000 08:01 43846485                   /usr/local/lib/openmpi/mca_coll_basic.so
7f751571d000-7f7515728000 r-xp 00000000 08:01 43846483                   /usr/local/lib/openmpi/mca_btl_tcp.so
7f7515728000-7f7515927000 ---p 0000b000 08:01 43846483                   /usr/local/lib/openmpi/mca_btl_tcp.so
7f7515927000-7f7515928000 r--p 0000a000 08:01 43846483                   /usr/local/lib/openmpi/mca_btl_tcp.so
7f7515928000-7f7515929000 rw-p 0000b000 08:01 43846483                   /usr/local/lib/openmpi/mca_btl_tcp.so
7f7515929000-7f75159a9000 rw-p 00000000 00:00 0 
7f75159a9000-7f75159af000 r-xp 00000000 08:01 43846477                   /usr/local/lib/openmpi/mca_btl_sm.so
7f75159af000-7f7515bae000 ---p 00006000 08:01 43846477                   /usr/local/lib/openmpi/mca_btl_sm.so
7f7515bae000-7f7515baf000 r--p 00005000 08:01 43846477                   /usr/local/lib/openmpi/mca_btl_sm.so
7f7515baf000-7f7515bb0000 rw-p 00006000 08:01 43846477                   /usr/local/lib/openmpi/mca_btl_sm.so
7f7515bb0000-7f7515bb3000 r-xp 00000000 08:01 43846475                   /usr/local/lib/openmpi/mca_btl_self.so
7f7515bb3000-7f7515db2000 ---p 00003000 08:01 43846475                   /usr/local/lib/openmpi/mca_btl_self.so
7f7515db2000-7f7515db3000 r--p 00002000 08:01 43846475                   /usr/local/lib/openmpi/mca_btl_self.so
7f7515db3000-7f7515db4000 rw-p 00003000 08:01 43846475                   /usr/local/lib/openmpi/mca_btl_self.so
7f75163fc000-7f7516400000 r-xp 00000000 08:01 43846473                   /usr/local/lib/openmpi/mca_bml_r2.so
7f7516400000-7f75165ff000 ---p 00004000 08:01 43846473                   /usr/local/lib/openmpi/mca_bml_r2.so
7f75165ff000-7f7516600000 r--p 00003000 08:01 43846473                   /usr/local/lib/openmpi/mca_bml_r2.so[wm:17807] *** Process received signal ***
[wm:17807] Signal: Aborted (6)
[wm:17807] Signal code:  (-6)
[wm:17807] [ 0] /lib/libpthread.so.0(+0xf8f0) [0x7f751bc0f8f0]
[wm:17807] [ 1] /lib/libc.so.6(gsignal+0x35) [0x7f751b8b1a75]
[wm:17807] [ 2] /lib/libc.so.6(abort+0x180) [0x7f751b8b55c0]
[wm:17807] [ 3] /lib/libc.so.6(+0x6d4fb) [0x7f751b8eb4fb]
[wm:17807] [ 4] /lib/libc.so.6(+0x775b6) [0x7f751b8f55b6]
[wm:17807] [ 5] /lib/libc.so.6(cfree+0x73) [0x7f751b8fbe53]
[wm:17807] [ 6] /home/pietro/FEniCS/lib/libdolfin.so.0(_ZN6dolfin7UFCCellD1Ev+0x51) [0x7f7523c6fdc1]
[wm:17807] [ 7] /home/pietro/FEniCS/lib/libdolfin.so.0(_ZNK6dolfin8Function21compute_vertex_valuesERNS_5ArrayIdEERKNS_4MeshE+0x6c8) [0x7f7523cb8d08]
[wm:17807] [ 8] /home/pietro/FEniCS/lib/libdolfin.so.0(_ZNK6dolfin7VTKFile16write_point_dataERKNS_15GenericFunctionERKNS_4MeshESs+0x123) [0x7f7523cd43d3]
[wm:17807] [ 9] /home/pietro/FEniCS/lib/libdolfin.so.0(_ZNK6dolfin7VTKFile13results_writeERKNS_8FunctionESs+0xdc) [0x7f7523cd594c]
[wm:17807] [10] /home/pietro/FEniCS/lib/libdolfin.so.0(_ZN6dolfin7VTKFilelsERKNS_8FunctionE+0x87) [0x7f7523cd7347]
[wm:17807] [11] ./colour_mesh(main+0x805) [0x417fa5]
[wm:17807] [12] /lib/libc.so.6(__libc_start_main+0xfd) [0x7f751b89cc4d]
[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



-- 
You received this question notification because you are a member of
DOLFIN Team, which is an answer contact for DOLFIN.