Changeset 11609:8f3dd402b200 in orange


Ignore:
Timestamp:
07/01/13 16:27:01 (10 months ago)
Author:
Ales Erjavec <ales.erjavec@…>
Branch:
default
Message:

Fixed a memory leak when raising an exception.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • source/orange/libsvm_interface.cpp

    r11608 r11609  
    635635    svm_node* x_space; 
    636636 
     637    PDomain domain = examples->domain; 
     638 
     639    int classVarType; 
     640    if (domain->classVar) 
     641        classVarType = domain->classVar->varType; 
     642    else { 
     643        classVarType = TValue::NONE; 
     644        if(svm_type != ONE_CLASS) 
     645            raiseError("Domain has no class variable"); 
     646    } 
     647    if (classVarType == TValue::FLOATVAR && !(svm_type == EPSILON_SVR || svm_type == NU_SVR ||svm_type == ONE_CLASS)) 
     648        raiseError("Domain has continuous class"); 
     649 
     650    if (kernel_type == PRECOMPUTED && !kernelFunc) 
     651        raiseError("Custom kernel function not supplied"); 
     652 
     653    PExampleTable train_data = mlnew TExampleTable(examples, /* owns= */ false); 
     654 
     655    if (classVarType == TValue::INTVAR && svm_type != ONE_CLASS) { 
     656        /* Sort the train data by the class columns so the order of 
     657         * classVar.values is preserved in libsvm's model. 
     658         */ 
     659        vector<int> sort_columns(domain->variables->size() - 1); 
     660        train_data->sort(sort_columns); 
     661    } 
     662 
     663    // Initialize svm parameters 
    637664    param.svm_type = svm_type; 
    638665    param.kernel_type = kernel_type; 
     
    644671    param.eps = eps; 
    645672    param.p = p; 
    646     param.cache_size=cache_size; 
    647     param.shrinking=shrinking; 
    648     param.probability=probability; 
     673    param.cache_size = cache_size; 
     674    param.shrinking = shrinking; 
     675    param.probability = probability; 
    649676    param.nr_weight = nr_weight; 
    650677 
     
    662689    } 
    663690 
    664     PDomain domain = examples->domain; 
    665  
    666     int classVarType; 
    667     if (domain->classVar) 
    668         classVarType = domain->classVar->varType; 
    669     else{ 
    670         classVarType = TValue::NONE; 
    671         if(svm_type != ONE_CLASS) 
    672             raiseError("Domain has no class variable"); 
    673     } 
    674     if (classVarType == TValue::FLOATVAR && !(svm_type == EPSILON_SVR || svm_type == NU_SVR ||svm_type == ONE_CLASS)) 
    675         raiseError("Domain has continuous class"); 
    676  
    677     if (kernel_type == PRECOMPUTED && !kernelFunc) 
    678         raiseError("Custom kernel function not supplied"); 
    679  
    680     PExampleTable train_data = mlnew TExampleTable(examples, /* owns= */ false); 
    681  
    682     if (classVarType == TValue::INTVAR && svm_type != ONE_CLASS) { 
    683         /* Sort the train data by the class columns so the order of 
    684          * classVar.values is preserved in libsvm's model. 
    685          */ 
    686         vector<int> sort_columns(domain->variables->size() - 1); 
    687         train_data->sort(sort_columns); 
    688     } 
    689  
    690691    int numElements = getNumOfElements(train_data); 
     692 
     693    prob.x = NULL; 
     694    prob.y = NULL; 
    691695 
    692696    if (kernel_type != PRECOMPUTED) 
     
    698702        param.gamma=1.0f/(float(numElements)/float(prob.l)-1); 
    699703 
    700     const char* error=svm_check_parameter(&prob,&param); 
     704    const char* error=svm_check_parameter(&prob, &param); 
    701705    if (error){ 
    702706        free(x_space); 
    703707        free(prob.y); 
    704708        free(prob.x); 
     709        svm_destroy_param(&param); 
    705710        raiseError("LibSVM parameter error: %s", error); 
    706711    } 
     
    722727    if ((svm_type==C_SVC || svm_type==NU_SVC) && !model->nSV) { 
    723728        svm_free_and_destroy_model(&model); 
    724         if (x_space) { 
    725             free(x_space); 
    726         } 
     729        free(x_space); 
     730        free(prob.x); 
     731        free(prob.y); 
     732        svm_destroy_param(&param); 
    727733        raiseError("LibSVM returned no support vectors"); 
    728734    } 
Note: See TracChangeset for help on using the changeset viewer.