Hi
I am using sun solaris 5.9 operating system.Sometimes after reading from and while writing to file process size used to get increase.(it can be after 20th times 40 th time)
I doesn't happen always but some time.After putting print statements i identified the point.Can any body tell me whether it will going to come in memory leak or normal process usuage.If it comes under memory leak how to slove?I have marked the code below from where it used to get increase.
Appreciate ur input in this.I have tried flushing out o/p buffer.But result is same.
Waiting for any input...............
char mm2_fname [MAXNAMLEN];
char def_fname [MAXNAMLEN];
char temp [MAXNAMLEN];
char file_id [MAXNAMLEN];
char fileTime [MAXNAMLEN];
char latestTime [MAXNAMLEN];
char currentTime [MAXNAMLEN];
char* timeStamp=0;
DIR *dirMMII=0;
if((dirMMII = opendir(MMIIFilePath)) == NULL)
{
return ;
}
struct dirent *mm2_flist=0;
while((mm2_flist = readdir(dirMMII)) != NULL)
{
if(::strstr(mm2_flist->d_name,".") == NULL)
continue;
if(::strstr(mm2_flist->d_name,"pmC") != NULL)
{
char* mmII_token = strrchr(mm2_flist->d_name, '.');
if (mmII_token == 0)
{
continue;
}
int prefixLen = mmII_token - mm2_flist->d_name;
strncpy(file_id, mm2_flist->d_name, prefixLen);
file_id[prefixLen] = '\0';
strcpy(fileTime, mm2_flist->d_name+prefixLen+1);
int prefixLen2 = strlen(fileTime);
char* latestTime_token = fileTime + (prefixLen2-4);
strcpy(latestTime, latestTime_token);
char* currentTime_token = _collectionPeriod + (prefixLen2-4);
strcpy(currentTime, currentTime_token);
if (strcmp(latestTime, currentTime) > 0)
{
timeStamp = fileTime;
}
else
{
timeStamp = _collectionPeriod;
}
if ((strcmp(currentTime, "2330") == 0) && (strcmp(latestTime, "0000") == 0))
{
timeStamp = fileTime;
}
sprintf(mm2_fname,"%s/%s", MMIIFilePath, mm2_flist->d_name);
// build def filename
sprintf(def_fname,"%s/%s.%s", DefaultFilePath,file_id, timeStamp);
// open the file for read
ifstream fin(mm2_fname);
DBG(7,"Open for read file: " << mm2_fname);
if(!fin)
{
return ;
}
ofstream fout(def_fname, ios::app);
DBG(7,"Open for writing file: " << def_fname);
if(!fout)
{
return
}
// append the contents
DBG(7,"Reading from " << mm2_fname << " and writing into " << def_fname);
while( fin >> temp )
fout << temp << endl;<--- This is the point where process size increase
fin.close();
fout.close();
}
}
closedir(dirMMII);
return ;
}