Changeset 15694

Show
Ignore:
Timestamp:
26.05.2008 10:21:58 (12 years ago)
Author:
davidb
Message:

Straighted out code for freeing key.dptr. Now does this properly without the memory leak that used to be in the code

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • gsdl/trunk/src/gdbmedit/db2txt/db2txt.cpp

    r15674 r15694  
    6262  int block_size = 0, i; 
    6363  GDBM_FILE dbf; 
    64   datum key, value; 
     64  datum key, value, nextkey; 
    6565       
    6666  // sanity check 
     
    9393    free(value.dptr); 
    9494 
    95     // free(key.dptr); Can't do this because then gdbm_nextkey() doesn't work! 
    96     key = gdbm_nextkey (dbf, key); 
     95    /* get next key */ 
     96    nextkey = gdbm_nextkey (dbf, key); 
     97 
     98    /* free old key's dptr, otherwise causes memory leak */ 
     99    free(key.dptr);  
     100     
     101    /* can now safely copy content of nextkey into key */ 
     102    key = nextkey; 
    97103  } 
    98104