冷曦_sole 2015-04-10 13:28 采纳率: 0%
浏览 712

solaris 内存溢出问题

编译器版本
Reading specs from /usr/sfw/lib/gcc/sparc-sun-solaris2.10/3.4.3/specs
Configured with: /sfw10/builds/build/sfw10-patch/usr/src/cmd/gcc/gcc-3.4.3/configure --prefix=/usr/sfw --with-as=/usr/ccs/bin/as --without-gnu-as --with-ld=/usr/ccs/bin/ld --without-gnu-ld --enable-languages=c,c++ --enable-shared
Thread model: posix
gcc version 3.4.3 (csl-sol210-3_4-branch+sol_rpath)

test.h:
include
#include
#include
#include
#include
#include
#include
#define MAX_DATE_STR_LEN 30
#define SECONDS_PER_DAY 3600 * 24
#define PATH_TOKEN "/"
#define FILE_TYPE_DIR 0
#define FILE_TYPE_OTHER 1
#define FILE_TYPE_NORMAL_FILE 2
int const FILETYPECOUNT=6 ;
using namespace std;
using std::vector;
using std::string;
struct FileInfoSole{
string Name; /* \316\304\274\376\303\373 /
string Path; /
\316\304\274\376\302\267\276\266 /
string FullPath; /
\316\304\274\376\310\253\302\267\276\266 /
long FileId; /
\316\304\274\376\261\352\312\266 /
int Result; /
\264\246\300\355\275\341\271\373 /
int Reason; /
\322\354\263\243\324\255\322\362 /
string ReasonDesc; /
\322\354\263\243\303\350\312\366 /
int Type; /
\316\304\274\376\300\340\320\315 /
long Size; /
\316\304\274\376\263\244\266\310 /
string CreateTime; /
\264\264\275\250\310\325\306\332 /
string ErrFile; /
\264\355\316\363\316\304\274\376\303\373 /
string TmpErrFile; /
\301\331\312\261\264\355\316\363\316\304\274\376 */
string FileType;
};
typedef vector FileListSole;

test.cpp:
#include "test.h"
using namespace std;
int GetFileListSole(string dir, FileListSole &fileList,string substr, int flag);
string tttypes[FILETYPECOUNT]={"CUST","USER","RED","HT","LT","MH"};
int main(){
string dir="./so/";
FileListSole fileList;
string substr;
GetFileListSole(dir,fileList,substr,0);
return 0;
}
int GetFileListSole(string dir, FileListSole &fileList,string substr, int flag){
DIR *pDir = NULL;
if ( ( pDir = opendir(dir.c_str()) ) == NULL ){
return false;
}

    int      retCode = 0;
FileInfoSole fileInfoSole;
    cout<<"link sole"<<endl;
    cout<<fileInfoSole.Name<<endl;
    cout<<fileInfoSole.Name<<endl;
    cout<<fileInfoSole.Name<<endl;
    struct dirent  entry;
    struct dirent *result;
    cout<<"4"<<fileInfoSole.Name<<endl;
    //for( retCode = readdir_r( pDir, &entry, &result ); result != NULL && 0 == retCode; retCode = readdir_r( pDir, &entry, &result ) )
    retCode = readdir_r( pDir, &entry, &result );
    for(int i=0 ;i< 4;i++)
    {
            retCode = readdir_r( pDir, &entry, &result );
    cout<<"5"<<fileInfoSole.Name<<endl;//循环第一次时,程序在这个地方蹦会了,出现段错误,郁闷彻底,求大侠帮助
             if( strcmp( entry.d_name, "." ) == 0 ||strcmp( entry.d_name, "..") == 0)
             {
                    continue;
             }
    cout<<"testa"<<endl;
    cout<<fileInfoSole.Name<<endl;
    cout<<"---"<<endl;
            fileInfoSole.Name = entry.d_name;
    //      cout<<fileInfoSole.Name<<endl;
    cout<<"testb"<<endl;
            if (substr!="")
            {
                    if (fileInfoSole.Name.find(substr)==string::npos)
                    {
                            //printf("%s\n",fileInfoSole.Name.c_str());
                            continue;
                    }
                    else
                    {
                            //printf("%s\n",fileInfoSole.Name.c_str());
                            fileInfoSole.FileType=substr;
                    }
            }else
            {
                    fileInfoSole.FileType=string("");
                    for(int k=0;k<FILETYPECOUNT;k++)
                    {
                            if (fileInfoSole.Name.find(tttypes[k])!=string::npos)
                            {
                                    fileInfoSole.FileType=string(tttypes[k]);
                                    break;
                            }
                    }
            }
            //printf("%s\n",fileInfoSole.Name.c_str());
             fileInfoSole.Path = dir;
             fileInfoSole.FullPath.clear();
             fileInfoSole.FullPath.append(dir).append(PATH_TOKEN).append(entry.d_name);

            //GetFileInfo( fileInfoSole );
             if ( FILE_TYPE_NORMAL_FILE == fileInfoSole.Type ){
                 //fileList.push_back(fileInfoSole);
             }

             if ( FILE_TYPE_DIR == fileInfoSole.Type )
             {
                if (flag)
                {
                    GetFileListSole(fileInfoSole.FullPath,fileList,substr, flag);
                }
             }
    }
    closedir(pDir);
    cout<<"over"<<endl;
    return true;

}

so文件夹:
-bash-3.2$ ls -l so
total 0
-rw-r--r-- 1 bill bill 0 Apr 10 18:30 fileiiiiiiiiiiiiii
执行程序:
-bash-3.2$ ./a.out
link sole

4
5
Segmentation Fault (core dumped)
-bash-3.2$
我就想问程序到cout<<"5"<<fileInfoSole.Name<<endl;个语句是报段错误,我猜测是系统调用导致的内存泄露,于是我在程序
FileInfoSole fileInfoSole;和struct dirent entry; 之间放了一个int solearr[200];
数组,就不会出现段错误了或者把so文件夹下的文件fileiiiiiiiiiiiiii改成短一点的file的时就不会出现段错误了,请问这是什么原因导致的,有什么更好的办法解决这个问题,越详细细越好,等代大神解决.....

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥30 关于#java#的问题,请各位专家解答!
    • ¥30 vue+element根据数据循环生成多个table,如何实现最后一列 平均分 合并
    • ¥20 pcf8563时钟芯片不启振
    • ¥20 pip2.40更新pip2.43时报错
    • ¥15 换yum源但仍然用不了httpd
    • ¥50 C# 使用DEVMOD设置打印机首选项
    • ¥15 麒麟V10 arm安装gdal
    • ¥20 OPENVPN连接问题
    • ¥15 flask实现搜索框访问数据库
    • ¥15 mrk3399刷完安卓11后投屏调试只能显示一个设备