CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

Seg Fault using DynamicList

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By Gerry Kan

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 31, 2020, 10:12
Default Seg Fault using DynamicList
  #1
Senior Member
 
Gerry Kan's Avatar
 
Gerry Kan
Join Date: May 2016
Posts: 348
Rep Power: 10
Gerry Kan is on a distinguished road
Howdy Foamers:

I have a very simple OF application using OF 7.

Code:
#include "fvCFD.H"
#include "uniformDimensionedFields.H"
#include "turbulentFluidThermoModel.H"
#include "rhoReactionThermo.H"
#include "ReactionModel.H"
#include "multivariateScheme.H"
#include "pimpleControl.H"
#include "pressureControl.H"
#include "fvOptions.H"
#include "localEulerDdtScheme.H"
#include "fvcSmooth.H"

DynamicList<Foam::word> wordDynList(0);

int main ( int argc, char *argv[] )  {
    wordDynList.append ( "one" );
    wordDynList.append ( "two" );
    Info << wordDynList << endl;
}
The code compiled but at the end of execution it gave me a seg fault:

Code:
2
(
one
two
)

Segmentation fault
Looking at test suite (Test-DynamicList.C) I could not do anything obvious that would cause the code to crash, nor did I see any any dynamic list being explicitly deallocated (not that it solved the problem). What else did I miss?

Thanks in advance, Gerry.
Gerry Kan is offline   Reply With Quote

Old   July 31, 2020, 10:29
Default
  #2
Senior Member
 
Gerry Kan's Avatar
 
Gerry Kan
Join Date: May 2016
Posts: 348
Rep Power: 10
Gerry Kan is on a distinguished road
It looks like the culprit is in the .append() function. I don't know why, though.
Gerry Kan is offline   Reply With Quote

Old   July 31, 2020, 10:47
Default
  #3
Senior Member
 
Gerry Kan's Avatar
 
Gerry Kan
Join Date: May 2016
Posts: 348
Rep Power: 10
Gerry Kan is on a distinguished road
Okay, it turns out I needed to deallocate the DynamicList afterall ...

Code:
#include "fvCFD.H"
#include "uniformDimensionedFields.H"
#include "turbulentFluidThermoModel.H"
#include "rhoReactionThermo.H"
#include "ReactionModel.H"
#include "multivariateScheme.H"
#include "pimpleControl.H"
#include "pressureControl.H"
#include "fvOptions.H"
#include "localEulerDdtScheme.H"
#include "fvcSmooth.H"

DynamicList<Foam::word> wordDynList(0);

int main ( int argc, char *argv[] )  {
    wordDynList.append ( "one" );
    wordDynList.append ( "two" );
    Info << wordDynList << endl;
    wordDynList.clearStorage();
}
Note that calling DynamicList::clear() is not enough, DynamicList::clearStorage() resets the list size to zero and free its current contents.

Gerry.
Weitao Liu likes this.
Gerry Kan is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Seg fault when accessing cell face velocities F_U, F_V, F_W oayeni1 Fluent UDF and Scheme Programming 0 December 19, 2013 15:55
v2.0.8 seg fault occurs after convergence is achieved newToSU2 SU2 4 November 27, 2013 06:21
all rans and navierstokes test cases getting seg fault jentink SU2 14 October 9, 2013 14:07
interDyMFoam in OF 2.0.1 : seg fault during mesh refinement michaelb OpenFOAM Running, Solving & CFD 3 July 2, 2012 08:16
Workbench 11-Linux Intel EM64T platforms Seg fault Maciej Karczewski CFX 5 April 19, 2010 03:37


All times are GMT -4. The time now is 20:30.