Changeset 442

Show
Ignore:
Timestamp:
08/26/09 18:35:44 (15 years ago)
Author:
bhilburn
Message:

Fixed a memory leak (and redundant memory allocation), and moved the
internal storage of SML_Config to a std::string to prevent a segfault.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • vtcross/trunk/src/service_management_layer/ServiceManagementLayer.cpp

    r441 r442  
    2828 
    2929#include <cmath> 
     30#include <cstdio> 
     31#include <cstdlib> 
    3032#include <cstring> 
    31 #include <stdlib.h> 
    32 #include <string.h> 
    33 #include <stdio.h> 
    3433#include <stdint.h> 
    3534 
     
    4039#include <fcntl.h> 
    4140#include <sqlite3.h> 
     41#include <string> 
    4242#include <sys/ioctl.h> 
    4343#include <sys/mman.h> 
     
    8080services_DB _services_DB; 
    8181data_DB _data_DB; 
    82 const char *_SML_Config; 
     82string _SML_Config; 
    8383bool shellFound; 
    8484 
     
    142142} 
    143143 
    144 //Note that sizes of CE_List, miss, and service are hardcoded for now. 
    145 //Also, their sizes are hardcoded into the code in various places; a fix for a future version. 
     144/* Note that sizes of CE_List, miss, and service are hardcoded for now. 
     145 * Also, their sizes are hardcoded into the code in various places; a fix  
     146 * for a future version. */ 
    146147ServiceManagementLayer::ServiceManagementLayer(const char* SML_Config, \ 
    147148    const char* serverName, const char* serverPort, int16_t clientPort) 
    148149{ 
    149150    LOG("Creating Service Management Layer.\n"); 
    150     _SML_Config = SML_Config; 
     151 
     152    _SML_Config = string(SML_Config); 
    151153    SMLport = clientPort; 
    152154 
    153155    ConnectToShell(serverName, serverPort); 
    154     CE_List = (CE_Reg *) malloc(10*sizeof(struct CE_Reg)); 
    155156    CE_List = new CE_Reg[10]; 
    156157 
    157158    miss = new Mission[10]; 
    158     for(int i = 0; i < 10; i++) 
     159    for(size_t i = 0; i < 10; i++) 
    159160        miss[i].services = new Service[30]; 
    160161 
     
    162163 
    163164    LoadConfiguration(SML_Config, miss); 
     165 
    164166    CreateServicesDB(); 
    165167    CreateDataDB(); 
     
    13991401    for(int i = 0; i < 10; i++) 
    14001402        miss[i].services = new Service[30]; 
    1401     LoadConfiguration(_SML_Config, miss); 
     1403    LoadConfiguration(_SML_Config.c_str(), miss); 
    14021404} 
    14031405