Changeset 432

Show
Ignore:
Timestamp:
08/25/09 13:15:46 (15 years ago)
Author:
bhilburn
Message:

Fixed a memery allocation issue that might have segfaulted, and a memory
leak.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • vtcross/trunk/src/shell/CognitiveRadioShell.cpp

    r420 r432  
    5353    CE_present = false; 
    5454 
    55     // TODO =BUG= The params, observables, and utils arrays are not being 
    56     // allocated here. If an shell object is constructed, and then immediately 
    57     // destructed, there will be no allocated memory, and the delete operater 
    58     // will receive a null pointer, which will segfault. 
    59 } 
    60  
    61  
    62 CognitiveRadioShell::~CognitiveRadioShell() 
    63 { 
    64     delete [] params; 
    65     delete [] observables; 
    66     delete [] utils; 
    67 } 
    68  
    69  
    70 CognitiveRadioShell::CognitiveRadioShell(const char* radioConfig, int16_t p1, \ 
    71         int16_t p2, int16_t p3) 
    72 { 
    73     LOG("Creating Cognitive Radio Shell.\n"); 
    74  
     55    /* These allocations must be done here to prevent a segfault should the 
     56     * shell be constructed then immediately destructed. */ 
    7557    params = new Parameter[10]; 
    7658    observables = new Observable[10]; 
    7759    utils = new Utility[10]; 
    7860    radio_info = new Radio_Info; 
    79  
     61} 
     62 
     63 
     64CognitiveRadioShell::~CognitiveRadioShell() 
     65{ 
     66    delete [] params; 
     67    delete [] observables; 
     68    delete [] utils; 
     69    delete Radio_Info; 
     70} 
     71 
     72 
     73CognitiveRadioShell::CognitiveRadioShell(const char* radioConfig, int16_t p1, \ 
     74        int16_t p2, int16_t p3) 
     75{ 
     76    LOG("Creating Cognitive Radio Shell.\n"); 
    8077    LoadRadioConfiguration(radioConfig, params, utils, observables, radio_info); 
    8178 
     
    652649 
    653650 
    654 int 
     651int32_t 
    655652CognitiveRadioShell::HandleMessage(int32_t socketFD) 
    656653{