Changeset 24047


Ignore:
Timestamp:
05/19/11 12:10:52 (10 years ago)
Author:
jmt12
Message:

I'd misunderstood where I needed to free the memory allocated to storing char*s in the TDB_DATA. Apparently I only have to free them when they are returned by tdb_fetch() or similar. Removed segfault causing calls to free()

Location:
gs2-extensions/tdb-edit/trunk/src/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • gs2-extensions/tdb-edit/trunk/src/src/tdbget-src/tdbget.cpp

    r24042 r24047  
    5050printUsage (char *program_name)
    5151{
    52   cerr << "usage: " << program_name << " <database_path> <key>" << endl;
    53   cerr << endl;
     52  cerr << "usage: " << program_name << " <database_path> <key>" << endl << endl;
    5453}
    5554/** printUsage() **/
     
    9291    }
    9392    cout << endl; // used to be printf("\n");
     93    // caller responsible for freeing this memory
    9494    free(value.dptr);
    9595  }
     
    9898    cout << endl; // used to be printf("\n");
    9999  }
    100   free(key.dptr);
    101100
    102101  tdb_close (tdb);
  • gs2-extensions/tdb-edit/trunk/src/src/tdbkeys-src/tdbkeys.cpp

    r24036 r24047  
    4747/**
    4848 */
    49 void 
    50 printUsage(char *program_name) 
     49void
     50printUsage(char *program_name)
    5151{
    5252  cerr << "usage: " << program_name << " <database_path>" << endl << endl;
     
    5959 *  @param argv - and char * array containing first the executable name, then
    6060 *                the name of/path to the database
    61  *  @return 0 
     61 *  @return 0
    6262 */
    6363int
     
    7676  int hash_size = 0;
    7777  int tdb_flags = TDB_DEFAULT;
    78   int open_flags = O_RDONLY; 
     78  int open_flags = O_RDONLY;
    7979  TDB_CONTEXT *tdb = tdb_open(dbname, hash_size, tdb_flags, open_flags, 0664);
    8080  if (!tdb)
     
    9797
    9898    /* free old key's dptr, otherwise causes memory leak */
    99     free(key.dptr); 
    100    
     99    free(key.dptr);
     100
    101101    /* can now safely copy content of nextkey into key */
    102102    key = nextkey;
    103103  }
    104  
     104
    105105  tdb_close(tdb);
    106106
  • gs2-extensions/tdb-edit/trunk/src/src/tdbset-src/tdbset.cpp

    r24039 r24047  
    7474  int tdb_flags = TDB_DEFAULT; // Default = 0
    7575  int tdb_store_flags = TDB_DEFAULT; // used later when storing
    76   int open_flags = O_RDWR;
     76  int open_flags = O_RDWR | O_CREAT;
    7777  TDB_CONTEXT *tdb = tdb_open(dbname, hash_size, tdb_flags, open_flags, 0664);
    7878  if (!tdb)
     
    123123      }
    124124
     125      // I'm responsible for freeing some memory
    125126      delete [] concat_data;
    126       free(concat_value_data.dptr);
    127127      free(original_value_data.dptr);
    128128    }
     
    144144      cerr << "failed to set [" << argv[2] << "] to '" << argv[3] << "'" << endl;
    145145    }
    146 
    147     free(value_data.dptr);
    148146  }
    149147  // only given a key? that's a deleting
     
    156154  }
    157155
    158   free(key_data.dptr);
    159 
    160156  tdb_close(tdb);
    161157
Note: See TracChangeset for help on using the changeset viewer.