LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

dynamic memory is corrupt

I have two Ini_New(0) inside same funtion. i will dispose one Ini handler before i initiate another one. However, i received error "dynamic memory is corrupted" when i try to read .ini file using Ini handler created second time. I already dispose the first handler. I tried using different handler name but the same case appear. I need to read two Ini file, so please advice on how to solve the error or suggest me alternative way to do it.
 
thanks
0 Kudos
Message 1 of 4
(3,993 Views)

please ignore the previous post as i make mistake with my question

the actual problem is as below.

   IniFile = Ini_New(0);
   MakePathname(StrPrjDir,"Temp.ini",StrFilePath);


   if(Ini_ReadFromFile(IniFile,StrFilePath)==0);
   {
    strcat(StrDFFileDir,"\\"); strcat(StrDFFileDir,StrDFFileName);
    fpFile = fopen (StrDFFileDir, "r");
    
    if(fpFile!=NULL)
    {
     startRead = 1;
     do
     {
        memset(StrBuffer, 0, 500);     
        sdata = fgets(StrBuffer, 500, fpFile);
        if(!startRead)
       {
            if(sdata!=NULL)
           {
                    for(i=0;i<12;i++)
                     {   ..........
                      }
                   strcpy(SectionName,"Penang:"); strcat(SectionName,StrText[1]);
                   if(Ini_SectionExists(IniFile,SectionName))
                   {      

                         ..............   
                          if(dCompare2>dCompare)
                         {
                               for (i=0;i<11;i++)
                                       Ini_PutRawString(IniFile,SectionName,Items[i],StrText[i]);
                          }
                        else if(dCompare2==dCompare)
                         {
                                if(dCompare2>dCompare)
                               {
                                      for (i=0;i<11;i++)
                                        Ini_PutRawString(IniFile,SectionName,Items[i],StrText[i]);
                               }

                         }
                  }
                 else
                 {
                       for (i=0;i<11;i++)
                             Ini_PutRawString(IniFile,SectionName,Items[i],StrText[i]); 
                 }
        ...........

I had encounter dynamic memory is corrupted when the last Ini_PutRawString is executed. Does this problem related to the fopen and Ini_New()? As i used both ini file and txt file in the above instruction.

Anyone, please advise.

0 Kudos
Message 2 of 4
(3,980 Views)

Hey popcorn,

I'm a bit confused now that you've asked two different questions.  What is it exactly that you're trying to accomplish - reading from two INI files at the same time?

This help article describes the reasons why you'll receive a "Dynamic Memory is Corrupt" error message.

Perhaps it would be best to post a small example that I can run that demonstrates this error?  The code you posted earlier uses a lot of variables and logic that I believe is not pertinent to replicating the issue.  Could you create a small example and post the file to this thread so that I can replicate this on my machine?

 
Derrick S.
Product Manager
NI DIAdem
National Instruments
0 Kudos
Message 3 of 4
(3,927 Views)
I tried to generate a sample code for you to test. I create simple timer loop with Ini_ReadFromFile(). When i run on that sample code, no msg of dynamic memory is corrupt occur. Then i found out that i change StrDFFileName somewhere inside timer loop that caused dynamic memory error when the timer loop run second time.
 
Thanks alot in helping me find the problem. 
0 Kudos
Message 4 of 4
(3,905 Views)