Changeset 61812


Ignore:
Timestamp:
Sep 5, 2014, 7:42:55 PM (10 years ago)
Author:
wenzeslaus
Message:

r.li: fix memory handling (memory leak in avl_to_array function)

avl_to_array function was allocating one by one structures which were already allocated by callers. Callers were not freeing the memory allocated for structures. Also avl_to_array function was not respecting the size and type of the passed array, so the dereferencing was probbaly not working correctly. The type of array passed to the function is now AVL_table, not the pointer to it, because this is already a pointer.

The influenced modules now should run faster, for small resolutions, and with better (correct) results.

The naming of AVL_table and AVL_tableRow is still strange.

Location:
grass/trunk/raster/r.li
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • grass/trunk/raster/r.li/r.li.daemon/avl.c

    r59044 r61812  
    194194
    195195
    196 long avl_to_array(avl_node * root, long i, AVL_table * a)
     196long avl_to_array(avl_node * root, long i, AVL_table a)
    197197{
    198198
     
    202202            G_fatal_error("avl, avl_to_array: null value");
    203203        else {
    204             a[i] = G_malloc(sizeof(AVL_tableRow));
    205             a[i]->k = root->key;
    206             a[i]->tot = root->counter;
     204            //a[i] = G_malloc(sizeof(AVL_tableRow));
     205            a[i].k = root->key;
     206            a[i].tot = root->counter;
    207207            i++;
    208208            i = avl_to_array(root->right_child, i, a);
  • grass/trunk/raster/r.li/r.li.daemon/avl.h

    r59025 r61812  
    3838avl_node *avl_find(const avl_tree root, const generic_cell k);
    3939int avl_add(avl_tree * root, const generic_cell k, const long n);
    40 long avl_to_array(avl_node * root, long i, AVL_table * a);
     40long avl_to_array(avl_node * root, long i, AVL_table a);
    4141long howManyCell(const avl_tree root, const generic_cell k);
    4242
  • grass/trunk/raster/r.li/r.li.dominance/dominance.c

    r59170 r61812  
    124124
    125125    avl_tree albero = NULL;
    126     AVL_table *array;
     126    AVL_table array;
    127127    generic_cell uc;
    128128
     
    270270        shannon = 0;
    271271        for (i = 0; i < m; i++) {
    272             t = array[i]->tot;
     272            t = array[i].tot;
    273273            perc = t / area;
    274274            logarithm = log(perc);
     
    311311
    312312    avl_tree albero = NULL;
    313     AVL_table *array;
     313    AVL_table array;
    314314    generic_cell uc;
    315315
     
    457457        shannon = 0;
    458458        for (i = 0; i < m; i++) {
    459             t = array[i]->tot;
     459            t = array[i].tot;
    460460            perc = t / area;
    461461            logarithm = log(perc);
     
    498498
    499499    avl_tree albero = NULL;
    500     AVL_table *array;
     500    AVL_table array;
    501501    generic_cell uc;
    502502
     
    644644        shannon = 0;
    645645        for (i = 0; i < m; i++) {
    646             t = array[i]->tot;
     646            t = array[i].tot;
    647647            perc = t / area;
    648648            logarithm = log(perc);
  • grass/trunk/raster/r.li/r.li.pielou/pielou.c

    r59170 r61812  
    124124
    125125    avl_tree albero = NULL;
    126     AVL_table *array;
     126    AVL_table array;
    127127    generic_cell uc;
    128128
     
    270270        shannon = 0;
    271271        for (i = 0; i < m; i++) {
    272             t = array[i]->tot;
     272            t = array[i].tot;
    273273            perc = t / area;
    274274            logarithm = log(perc);
     
    311311
    312312    avl_tree albero = NULL;
    313     AVL_table *array;
     313    AVL_table array;
    314314    generic_cell uc;
    315315
     
    457457        shannon = 0;
    458458        for (i = 0; i < m; i++) {
    459             t = array[i]->tot;
     459            t = array[i].tot;
    460460            perc = t / area;
    461461            logarithm = log(perc);
     
    498498
    499499    avl_tree albero = NULL;
    500     AVL_table *array;
     500    AVL_table array;
    501501    generic_cell uc;
    502502
     
    644644        shannon = 0;
    645645        for (i = 0; i < m; i++) {
    646             t = array[i]->tot;
     646            t = array[i].tot;
    647647            perc = t / area;
    648648            logarithm = log(perc);
  • grass/trunk/raster/r.li/r.li.renyi/renyi.c

    r59300 r61812  
    148148
    149149    avl_tree albero = NULL;
    150     AVL_table *array;
     150    AVL_table array;
    151151    generic_cell uc;
    152152
     
    298298        sum2 = 0;
    299299        for (i = 0; i < m; i++) {
    300             t = array[i]->tot;
     300            t = array[i].tot;
    301301            pi = t / area;
    302302            sum += pow(pi, alpha);
     
    349349
    350350    avl_tree albero = NULL;
    351     AVL_table *array;
     351    AVL_table array;
    352352    generic_cell uc;
    353353
     
    499499        sum2 = 0;
    500500        for (i = 0; i < m; i++) {
    501             t = array[i]->tot;
     501            t = array[i].tot;
    502502            pi = t / area;
    503503            sum += pow(pi, alpha);
     
    550550
    551551    avl_tree albero = NULL;
    552     AVL_table *array;
     552    AVL_table array;
    553553    generic_cell uc;
    554554
     
    700700        sum2 = 0;
    701701        for (i = 0; i < m; i++) {
    702             t = array[i]->tot;
     702            t = array[i].tot;
    703703            pi = t / area;
    704704            sum += pow(pi, alpha);
  • grass/trunk/raster/r.li/r.li.shannon/shannon.c

    r59170 r61812  
    124124
    125125    avl_tree albero = NULL;
    126     AVL_table *array;
     126    AVL_table array;
     127    //AVL_tableRow *array;
    127128    generic_cell uc;
    128129
     
    270271        shannon = 0;
    271272        for (i = 0; i < m; i++) {
    272             t = array[i]->tot;
     273            t = array[i].tot;
    273274            perc = t / area;
    274275            logarithm = log(perc);
     
    311312
    312313    avl_tree albero = NULL;
    313     AVL_table *array;
     314    AVL_table array;
    314315    generic_cell uc;
    315316
     
    457458        shannon = 0;
    458459        for (i = 0; i < m; i++) {
    459             t = array[i]->tot;
     460            t = array[i].tot;
    460461            perc = t / area;
    461462            logarithm = log(perc);
     
    498499
    499500    avl_tree albero = NULL;
    500     AVL_table *array;
     501    AVL_table array;
    501502    generic_cell uc;
    502503
     
    644645        shannon = 0;
    645646        for (i = 0; i < m; i++) {
    646             t = array[i]->tot;
     647            t = array[i].tot;
    647648            perc = t / area;
    648649            logarithm = log(perc);
  • grass/trunk/raster/r.li/r.li.simpson/simpson.c

    r59170 r61812  
    124124
    125125    avl_tree albero = NULL;
    126     AVL_table *array;
     126    AVL_table array;
    127127    generic_cell uc;
    128128
     
    270270        simpson = 0;
    271271        for (i = 0; i < m; i++) {
    272             t = (double)(array[i]->tot);
     272            t = (double)(array[i].tot);
    273273            p = t / area;
    274274            simpson += (p * p);
     
    310310
    311311    avl_tree albero = NULL;
    312     AVL_table *array;
     312    AVL_table array;
    313313    generic_cell uc;
    314314
     
    456456        simpson = 0;
    457457        for (i = 0; i < m; i++) {
    458             t = (double)(array[i]->tot);
     458            t = (double)(array[i].tot);
    459459            p = t / area;
    460460            simpson += (p * p);
     
    496496
    497497    avl_tree albero = NULL;
    498     AVL_table *array;
     498    AVL_table array;
    499499    generic_cell uc;
    500500
     
    642642        simpson = 0;
    643643        for (i = 0; i < m; i++) {
    644             t = (double)(array[i]->tot);
     644            t = (double)(array[i].tot);
    645645            p = t / area;
    646646            simpson += (p * p);
Note: See TracChangeset for help on using the changeset viewer.