Changeset 679


Ignore:
Timestamp:
02/19/15 14:24:03 (3 years ago)
Author:
jls17
Message:
  • fixed some memory leaks in case memory allocation fails in ARFieldList.cpp and ARSchemaList.cpp
  • small changes to the initialization of the crash handler
Location:
branches/work_320
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • branches/work_320/ARInsideMain.cpp

    r666 r679  
    2121int main(int argc, char* argv[]) 
    2222{ 
     23        void *pCrashHandler = 
    2324#ifdef ARINSIDE_BREAKPAD_SUPPORT 
    24         CrashHandler crashHandler; 
     25                new CrashHandler(); 
     26#else 
     27                NULL; 
    2528#endif 
    2629        CMain theMain; 
     30        theMain.SetCrashHandler(pCrashHandler); 
    2731        return theMain.Run(argc, argv); 
    2832 
  • branches/work_320/CrashHandler.cpp

    r666 r679  
    7777{ 
    7878        cout << "Application crash! Mini dump written to: "; 
     79        cout.flush(); 
    7980#ifdef WIN32 
    8081  wcout << dump_path << minidump_id << L".dmp"; 
  • branches/work_320/Main.cpp

    r333 r679  
    3232int nFilesCreated; 
    3333 
     34CMain::CMain() 
     35{ 
     36        crashHandler = NULL; 
     37} 
     38 
    3439int CMain::Run(int argc, char* argv[]) 
    3540{ 
     
    4651 
    4752                string settingsIni = cmdLineValidator.GetIniFilename(); 
     53 
     54                if (crashHandler != NULL) 
     55                        LOG << "Crash handler is installed" << endl; 
    4856 
    4957                cout << endl << "Load application configuration settings: '" << settingsIni << "' " << endl; 
     
    133141 
    134142        return result; 
     143} 
     144 
     145void CMain::SetCrashHandler(void *pAddr) 
     146{ 
     147        crashHandler = pAddr; 
    135148} 
    136149 
  • branches/work_320/Main.h

    r333 r679  
    2525{ 
    2626public: 
     27        CMain(); 
     28        void SetCrashHandler(void *pAddr); 
    2729        int Run(int argc, char* argv[]); 
    2830 
     
    3840private: 
    3941        CAppTimer mTimer; 
     42        void*     crashHandler; 
    4043}; 
  • branches/work_320/lists/ARFieldList.cpp

    r675 r679  
    128128{ 
    129129        schemaId = schemaInsideId; 
     130        ClearAllStructs(); 
     131} 
     132 
     133CARFieldListServer::~CARFieldListServer() 
     134{ 
     135        FreeARNameList(&names, false); 
     136        FreeARInternalIdList(&fieldIds, false); 
     137        FreeARFieldMappingList(&fieldMaps, false); 
     138        FreeARUnsignedIntList(&dataTypes, false); 
     139        FreeARUnsignedIntList(&options, false); 
     140        FreeARUnsignedIntList(&createModes, false); 
     141        FreeARUnsignedIntList(&fieldOptions, false); 
     142        FreeARValueList(&defaultValues, false); 
     143        FreeARPermissionListList(&permLists, false); 
     144        FreeARFieldLimitList(&limits, false); 
     145        FreeARDisplayInstanceListList(&dInstanceLists, false); 
     146        FreeARTextStringList(&helpTexts, false); 
     147        FreeARTimestampList(&changedTimes, false); 
     148        FreeARAccessNameList(&owners, false); 
     149        FreeARAccessNameList(&changedUsers, false); 
     150        FreeARTextStringList(&changeDiary, false); 
     151} 
     152 
     153void CARFieldListServer::ClearAllStructs() 
     154{ 
    130155        ARZeroMemory(&names); 
    131156        ARZeroMemory(&fieldIds); 
     
    146171} 
    147172 
    148 CARFieldListServer::~CARFieldListServer() 
    149 { 
    150         FreeARNameList(&names, false); 
    151         FreeARInternalIdList(&fieldIds, false); 
    152         FreeARFieldMappingList(&fieldMaps, false); 
    153         FreeARUnsignedIntList(&dataTypes, false); 
    154         FreeARUnsignedIntList(&options, false); 
    155         FreeARUnsignedIntList(&createModes, false); 
    156         FreeARUnsignedIntList(&fieldOptions, false); 
    157         FreeARValueList(&defaultValues, false); 
    158         FreeARPermissionListList(&permLists, false); 
    159         FreeARFieldLimitList(&limits, false); 
    160         FreeARDisplayInstanceListList(&dInstanceLists, false); 
    161         FreeARTextStringList(&helpTexts, false); 
    162         FreeARTimestampList(&changedTimes, false); 
    163         FreeARAccessNameList(&owners, false); 
    164         FreeARAccessNameList(&changedUsers, false); 
    165         FreeARTextStringList(&changeDiary, false); 
    166 } 
    167  
    168173bool CARFieldListServer::LoadFromServer() 
    169174{ 
     
    174179 
    175180        memset(&fldExists, 0, sizeof(ARBooleanList)); 
    176         memset(&status, 0, sizeof(status)); 
     181        memset(&status, 0, sizeof(status));      
    177182 
    178183        if (!arIn->appConfig.slowObjectLoading && ARGetMultipleFields(&arIn->arControl, 
     
    323328void CARFieldListServer::Reserve(unsigned int amount) 
    324329{ 
    325         names.nameList = new ARNameType[amount]; 
    326         ARZeroMemory(names.nameList, sizeof(ARNameType) * amount); 
    327  
    328         fieldIds.internalIdList = new ARInternalId[amount]; 
    329         ARZeroMemory(fieldIds.internalIdList, sizeof(ARInternalId) * amount); 
    330  
    331         fieldMaps.mappingList = new ARFieldMappingStruct[amount]; 
    332         ARZeroMemory(fieldMaps.mappingList, sizeof(ARFieldMappingStruct) * amount); 
    333  
    334         dataTypes.intList = new unsigned int[amount]; 
    335         ARZeroMemory(dataTypes.intList, sizeof(unsigned int) * amount); 
    336  
    337         options.intList = new unsigned int[amount]; 
    338         ARZeroMemory(options.intList, sizeof(unsigned int) * amount); 
    339  
    340         createModes.intList = new unsigned int[amount]; 
    341         ARZeroMemory(createModes.intList, sizeof(unsigned int) * amount); 
    342          
    343         fieldOptions.intList = new unsigned int[amount]; 
    344         ARZeroMemory(fieldOptions.intList, sizeof(unsigned int) * amount); 
    345  
    346         defaultValues.valueList = new ARValueStruct[amount]; 
    347         ARZeroMemory(defaultValues.valueList, sizeof(ARValueStruct) * amount); 
    348  
    349         permLists.permissionList = new ARPermissionList[amount]; 
    350         ARZeroMemory(permLists.permissionList, sizeof(ARPermissionList) * amount); 
    351  
    352         limits.fieldLimitList = new ARFieldLimitStruct[amount]; 
    353         ARZeroMemory(limits.fieldLimitList, sizeof(ARFieldLimitStruct) * amount); 
    354  
    355         dInstanceLists.dInstanceList = new ARDisplayInstanceList[amount]; 
    356         ARZeroMemory(dInstanceLists.dInstanceList, sizeof(ARDisplayInstanceList) * amount); 
    357  
    358         helpTexts.stringList = new char*[amount]; 
    359         ARZeroMemory(helpTexts.stringList, sizeof(char*) * amount); 
    360  
    361         changedTimes.timestampList = new ARTimestamp[amount]; 
    362         ARZeroMemory(changedTimes.timestampList, sizeof(ARTimestamp) * amount); 
    363  
    364         owners.nameList = new ARAccessNameType[amount]; 
    365         ARZeroMemory(owners.nameList, sizeof(ARAccessNameType) * amount); 
    366  
    367         changedUsers.nameList = new ARAccessNameType[amount]; 
    368         ARZeroMemory(changedUsers.nameList, sizeof(ARAccessNameType) * amount); 
    369  
    370         changeDiary.stringList = new char*[amount]; 
    371         ARZeroMemory(changeDiary.stringList, sizeof(char*) * amount); 
    372  
    373 #if AR_CURRENT_API_VERSION >= AR_API_VERSION_763 
    374         objProps.propsList = new ARPropList[amount]; 
    375         ARZeroMemory(objProps.propsList, sizeof(ARPropList) * amount); 
    376 #endif 
     330        unsigned int objAllocIndex = 0; 
     331        try 
     332        { 
     333                names.nameList = new ARNameType[amount]; 
     334                ARZeroMemory(names.nameList, sizeof(ARNameType) * amount); 
     335                objAllocIndex++; 
     336 
     337                fieldIds.internalIdList = new ARInternalId[amount]; 
     338                ARZeroMemory(fieldIds.internalIdList, sizeof(ARInternalId) * amount); 
     339                objAllocIndex++; 
     340 
     341                fieldMaps.mappingList = new ARFieldMappingStruct[amount]; 
     342                ARZeroMemory(fieldMaps.mappingList, sizeof(ARFieldMappingStruct) * amount); 
     343                objAllocIndex++; 
     344 
     345                dataTypes.intList = new unsigned int[amount]; 
     346                ARZeroMemory(dataTypes.intList, sizeof(unsigned int) * amount); 
     347                objAllocIndex++; 
     348 
     349                options.intList = new unsigned int[amount]; 
     350                ARZeroMemory(options.intList, sizeof(unsigned int) * amount); 
     351                objAllocIndex++; 
     352 
     353                createModes.intList = new unsigned int[amount]; 
     354                ARZeroMemory(createModes.intList, sizeof(unsigned int) * amount); 
     355                objAllocIndex++; 
     356                 
     357                fieldOptions.intList = new unsigned int[amount]; 
     358                ARZeroMemory(fieldOptions.intList, sizeof(unsigned int) * amount); 
     359                objAllocIndex++; 
     360 
     361                defaultValues.valueList = new ARValueStruct[amount]; 
     362                ARZeroMemory(defaultValues.valueList, sizeof(ARValueStruct) * amount); 
     363                objAllocIndex++; 
     364 
     365                permLists.permissionList = new ARPermissionList[amount]; 
     366                ARZeroMemory(permLists.permissionList, sizeof(ARPermissionList) * amount); 
     367                objAllocIndex++; 
     368 
     369                limits.fieldLimitList = new ARFieldLimitStruct[amount]; 
     370                ARZeroMemory(limits.fieldLimitList, sizeof(ARFieldLimitStruct) * amount); 
     371                objAllocIndex++; 
     372 
     373                dInstanceLists.dInstanceList = new ARDisplayInstanceList[amount]; 
     374                ARZeroMemory(dInstanceLists.dInstanceList, sizeof(ARDisplayInstanceList) * amount); 
     375                objAllocIndex++; 
     376 
     377                helpTexts.stringList = new char*[amount]; 
     378                ARZeroMemory(helpTexts.stringList, sizeof(char*) * amount); 
     379                objAllocIndex++; 
     380 
     381                changedTimes.timestampList = new ARTimestamp[amount]; 
     382                ARZeroMemory(changedTimes.timestampList, sizeof(ARTimestamp) * amount); 
     383                objAllocIndex++; 
     384 
     385                owners.nameList = new ARAccessNameType[amount]; 
     386                ARZeroMemory(owners.nameList, sizeof(ARAccessNameType) * amount); 
     387                objAllocIndex++; 
     388 
     389                changedUsers.nameList = new ARAccessNameType[amount]; 
     390                ARZeroMemory(changedUsers.nameList, sizeof(ARAccessNameType) * amount); 
     391                objAllocIndex++; 
     392 
     393                changeDiary.stringList = new char*[amount]; 
     394                ARZeroMemory(changeDiary.stringList, sizeof(char*) * amount); 
     395                objAllocIndex++; 
     396 
     397#if AR_CURRENT_API_VERSION >= AR_API_VERSION_763 
     398                objProps.propsList = new ARPropList[amount]; 
     399                ARZeroMemory(objProps.propsList, sizeof(ARPropList) * amount); 
     400                objAllocIndex++; 
     401#endif 
     402        } 
     403        catch (exception &e) 
     404        { 
     405                cout << "Failed to allocate memory (" << e.what() << ") for " << CARInside::GetInstance()->schemaList.SchemaGetName(schemaId) << " [" << objAllocIndex << ", " << amount << "]" << endl; 
     406                delete[] objProps.propsList; 
     407                delete[] changeDiary.stringList; 
     408                delete[] changedUsers.nameList; 
     409                delete[] owners.nameList; 
     410                delete[] changedTimes.timestampList; 
     411                delete[] helpTexts.stringList; 
     412                delete[] dInstanceLists.dInstanceList; 
     413                delete[] limits.fieldLimitList; 
     414                delete[] permLists.permissionList; 
     415                delete[] defaultValues.valueList; 
     416                delete[] fieldOptions.intList; 
     417                delete[] createModes.intList; 
     418                delete[] options.intList; 
     419                delete[] dataTypes.intList; 
     420                delete[] fieldMaps.mappingList; 
     421                delete[] fieldIds.internalIdList; 
     422                delete[] names.nameList; 
     423                ClearAllStructs(); 
     424                throw; 
     425        } 
    377426} 
    378427 
  • branches/work_320/lists/ARFieldList.h

    r671 r679  
    152152        void SetNumItems(unsigned int amount); 
    153153        void BuildIndex(); 
     154        void ClearAllStructs(); 
    154155 
    155156private: 
  • branches/work_320/lists/ARSchemaList.cpp

    r675 r679  
    374374        for (unsigned int schemaIndex = 0; schemaIndex < count; ++schemaIndex) 
    375375        { 
    376                 CARFieldListServer *srvFieldList = new CARFieldListServer(schemaIndex); 
    377                 srvFieldList->LoadFromServer(); // TODO: maybe check if successfully loaded 
    378                 srvFieldList->Sort(); 
     376                CARFieldListServer *srvFieldList = NULL; 
     377                try 
     378                { 
     379                        srvFieldList = new CARFieldListServer(schemaIndex); 
     380                        srvFieldList->LoadFromServer(); // TODO: maybe check if successfully loaded 
     381                        srvFieldList->Sort(); 
     382                } 
     383                catch (exception &e) 
     384                { 
     385                        cerr << "FATAL: loading fields for '" << SchemaGetName(schemaIndex) << "' failed with: " << e.what() << endl; 
     386                        if (srvFieldList != NULL) { delete srvFieldList; } 
     387                        srvFieldList = new CARFieldListServer(schemaIndex); 
     388                } 
    379389                fieldLists.push_back(srvFieldList); 
    380390        } 
Note: See TracChangeset for help on using the changeset viewer.