Memory corruption error when accessing files?

Discussions about using Linux guests in VirtualBox.
Post Reply
PacMan
Posts: 4
Joined: 23. May 2014, 10:44

Memory corruption error when accessing files?

Post by PacMan »

Hello!

I'm running Ubuntu 12.04 on VirtualBox 4.3.12 on Mac OS X 10.9 as host. In the last few days I tried to solve some chemistry mechanisms with an extension to the open-source software Cantera 2.0.0. In my particular case, there is an input.txt file, which can be modified to define the boundary conditions. The software solves some equations and writes two files. The first one is there to store all the results of the calculation, the second one serves as the basis for the next run.

Whereas the calculation runs fine, I sometimes (depends on the entries in the input file) get an error when the program tries to access the files:

Code: Select all

*** glibc detected *** ./flamelet: malloc(): memory corruption: 0x0000000000e67360 ***
The numbers at the end differ from case to case.

I took a look at the code of this "flamelet" executable and localized the error. It might help you to have a look also, so I insert the important part of the code:

Code: Select all

    //-------Scalar Dissipation Rate calculation
    double a = sqrt(abs(solution(1,4))/ gas.density());
    double dissRate = 2.0*a/M_PI*exp(-2.0*pow(boost::math::erfc_inv(2.0*Z_st),2));

    cout << "Scalar Dissipation Rate: " << dissRate << " 1/s"<< endl;

    //-------Construct Filename
    ostringstream strs;
    strs << dissRate;
    std::string str_dissRate = strs.str();
    string strfile = "canteraTables/canteraTable_" + str_dissRate + ".csv";

    char * filename = new char[strfile.length()];
    strcpy(filename,strfile.c_str());

    // Print the flamelet table to be used in OPENFOAM
    ofstream myfile;
    myfile.open(filename);
    output_Excel(myfile, filename, names, solution);
 
    string title;
    string id;
    string desc;
    cout << "Do you want to write the initial guess file? press 1 for yes or 0 to no";
    cin >> log_num;

    if(log_num==1){
    remove ("solution.xml"); 
    flame.save(title= "solution.xml",id="id_01", desc="case_1");}
The error occurs at the lines "myfile.open(filename)" or "flame.save(title= "solution.xml",id="id_01", desc="case_1")", depending on which one is executed first (I changed the order as a test). I tried to run the code with the same boundary conditions on another system with ubuntu running as OS and it worked fine. Thats why I assume that there is a VirtualBox problem managing the memory.

Can someone please help me with my current problem? Many thanks in advance!
socratis
Site Moderator
Posts: 27329
Joined: 22. Oct 2010, 11:03
Primary OS: Mac OS X other
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Win(*>98), Linux*, OSX>10.5
Location: Greece

Re: Memory corruption error when accessing files?

Post by socratis »

Where is the file that you want to open or save located at? Is it in a shared folder maybe?
Do NOT send me Personal Messages (PMs) for troubleshooting, they are simply deleted.
Do NOT reply with the "QUOTE" button, please use the "POST REPLY", at the bottom of the form.
If you obfuscate any information requested, I will obfuscate my response. These are virtual UUIDs, not real ones.
PacMan
Posts: 4
Joined: 23. May 2014, 10:44

Re: Memory corruption error when accessing files?

Post by PacMan »

socratis wrote:Where is the file that you want to open or save located at? Is it in a shared folder maybe?
At first I have to say that I'm not exactly sure what this myfile.open function does, because I'm not an expert in C++. To answer your question, the solution file is located in the same folder as the flamelet executable. No shared folders...

In addition I have to mention that everything works fine sometimes, depending on the entries in the input file. Unfortunately I can't figure out why.
socratis
Site Moderator
Posts: 27329
Joined: 22. Oct 2010, 11:03
Primary OS: Mac OS X other
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Win(*>98), Linux*, OSX>10.5
Location: Greece

Re: Memory corruption error when accessing files?

Post by socratis »

If there are no VirtualBox features involved (such as shared folders), and it works sometimes, I would look for the problem in your code and/or your setup. Maybe the memory of your guest is indeed too low?
Do NOT send me Personal Messages (PMs) for troubleshooting, they are simply deleted.
Do NOT reply with the "QUOTE" button, please use the "POST REPLY", at the bottom of the form.
If you obfuscate any information requested, I will obfuscate my response. These are virtual UUIDs, not real ones.
PacMan
Posts: 4
Joined: 23. May 2014, 10:44

Re: Memory corruption error when accessing files?

Post by PacMan »

socratis wrote:Maybe the memory of your guest is indeed too low?
My system has 8 GB of memory, the VM usually uses 2 GB. I also tried with 4 GB, changed nothing.
smithlar
Posts: 79
Joined: 9. May 2008, 15:54
Primary OS: openSUSE
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: WinXP32 WinXP64 Win7-32 Win7-64 openSUSE64 OS2 Win10
Location: Texas, USA

Re: Memory corruption error when accessing files?

Post by smithlar »

"filename" should have room for the trailing nul byte of a Std C string,
like this:

Code: Select all

char * filename = new char[strfile.length() + 1];
PacMan
Posts: 4
Joined: 23. May 2014, 10:44

Re: Memory corruption error when accessing files?

Post by PacMan »

smithlar wrote:"filename" should have room for the trailing nul byte of a Std C string,
like this:

Code: Select all

char * filename = new char[strfile.length() + 1];
Seems to be working fine, thank you very very much! :wink:
Post Reply