diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-08-26 12:48:07 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-08-26 12:48:07 +0000 |
commit | 939d23ccbb6ec5753d141f325339529b9b2e4f80 (patch) | |
tree | b9e28118f8d50786a9c4f9bb41e068a89e0aefe6 /src/namestore | |
parent | 45bfd221049cb73f835429f35371dbf2dfe7416f (diff) | |
download | gnunet-939d23ccbb6ec5753d141f325339529b9b2e4f80.tar.gz gnunet-939d23ccbb6ec5753d141f325339529b9b2e4f80.zip |
fix memory leak and unnecessary allocations
Diffstat (limited to 'src/namestore')
-rw-r--r-- | src/namestore/plugin_namestore_flat.c | 52 |
1 files changed, 23 insertions, 29 deletions
diff --git a/src/namestore/plugin_namestore_flat.c b/src/namestore/plugin_namestore_flat.c index 36b045394..b522fc031 100644 --- a/src/namestore/plugin_namestore_flat.c +++ b/src/namestore/plugin_namestore_flat.c | |||
@@ -142,10 +142,10 @@ database_setup (struct Plugin *plugin) | |||
142 | size_t key_len; | 142 | size_t key_len; |
143 | struct GNUNET_HashCode hkey; | 143 | struct GNUNET_HashCode hkey; |
144 | struct GNUNET_DISK_FileHandle *fh; | 144 | struct GNUNET_DISK_FileHandle *fh; |
145 | struct FlatFileEntry *entry; | 145 | struct FlatFileEntry *entry; |
146 | 146 | ||
147 | if (GNUNET_OK != | 147 | if (GNUNET_OK != |
148 | GNUNET_CONFIGURATION_get_value_filename (plugin->cfg, | 148 | GNUNET_CONFIGURATION_get_value_filename (plugin->cfg, |
149 | "namestore-flat", | 149 | "namestore-flat", |
150 | "FILENAME", &afsdir)) | 150 | "FILENAME", &afsdir)) |
151 | { | 151 | { |
@@ -243,7 +243,7 @@ database_setup (struct Plugin *plugin) | |||
243 | record_data_size = GNUNET_STRINGS_base64_decode (record_data_b64, | 243 | record_data_size = GNUNET_STRINGS_base64_decode (record_data_b64, |
244 | strlen (record_data_b64), | 244 | strlen (record_data_b64), |
245 | &record_data); | 245 | &record_data); |
246 | entry->record_data = | 246 | entry->record_data = |
247 | GNUNET_malloc (sizeof (struct GNUNET_GNSRECORD_Data) * entry->record_count); | 247 | GNUNET_malloc (sizeof (struct GNUNET_GNSRECORD_Data) * entry->record_count); |
248 | if (GNUNET_OK != GNUNET_GNSRECORD_records_deserialize (record_data_size, | 248 | if (GNUNET_OK != GNUNET_GNSRECORD_records_deserialize (record_data_size, |
249 | record_data, | 249 | record_data, |
@@ -271,7 +271,7 @@ database_setup (struct Plugin *plugin) | |||
271 | key_len, | 271 | key_len, |
272 | &hkey); | 272 | &hkey); |
273 | GNUNET_free (key); | 273 | GNUNET_free (key); |
274 | if (GNUNET_OK != | 274 | if (GNUNET_OK != |
275 | GNUNET_CONTAINER_multihashmap_put (plugin->hm, | 275 | GNUNET_CONTAINER_multihashmap_put (plugin->hm, |
276 | &hkey, | 276 | &hkey, |
277 | entry, | 277 | entry, |
@@ -301,46 +301,40 @@ store_and_free_entries (void *cls, | |||
301 | struct FlatFileEntry *entry = value; | 301 | struct FlatFileEntry *entry = value; |
302 | char *line; | 302 | char *line; |
303 | char *zone_private_key; | 303 | char *zone_private_key; |
304 | char *rvalue; | ||
305 | char *record_count; | ||
306 | char *record_data_b64; | 304 | char *record_data_b64; |
307 | size_t data_size; | 305 | size_t data_size; |
308 | 306 | ||
309 | GNUNET_STRINGS_base64_encode ((char*)entry->private_key, | 307 | GNUNET_STRINGS_base64_encode ((char*)entry->private_key, |
310 | sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey), | 308 | sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey), |
311 | &zone_private_key); | 309 | &zone_private_key); |
312 | GNUNET_asprintf (&rvalue, "%lu", entry->rvalue); | ||
313 | GNUNET_asprintf (&record_count, "%u", entry->record_count); | ||
314 | |||
315 | data_size = GNUNET_GNSRECORD_records_get_size (entry->record_count, | 310 | data_size = GNUNET_GNSRECORD_records_get_size (entry->record_count, |
316 | entry->record_data); | 311 | entry->record_data); |
317 | char data[data_size]; | ||
318 | if (data_size != GNUNET_GNSRECORD_records_serialize (entry->record_count, | ||
319 | entry->record_data, | ||
320 | data_size, | ||
321 | data)) | ||
322 | { | 312 | { |
323 | GNUNET_break (0); | 313 | char data[data_size]; |
324 | GNUNET_free (zone_private_key); | ||
325 | GNUNET_free (rvalue); | ||
326 | GNUNET_free (record_count); | ||
327 | return GNUNET_SYSERR; | ||
328 | } | ||
329 | GNUNET_STRINGS_base64_encode (data, | ||
330 | data_size, | ||
331 | &record_data_b64); | ||
332 | 314 | ||
315 | if (data_size != | ||
316 | GNUNET_GNSRECORD_records_serialize (entry->record_count, | ||
317 | entry->record_data, | ||
318 | data_size, | ||
319 | data)) | ||
320 | { | ||
321 | GNUNET_break (0); | ||
322 | GNUNET_free (zone_private_key); | ||
323 | return GNUNET_SYSERR; | ||
324 | } | ||
325 | GNUNET_STRINGS_base64_encode (data, | ||
326 | data_size, | ||
327 | &record_data_b64); | ||
328 | } | ||
333 | GNUNET_asprintf (&line, | 329 | GNUNET_asprintf (&line, |
334 | "%s,%s,%s,%s,%s\n", | 330 | "%s,%lu,%u,%s,%s\n", |
335 | zone_private_key, | 331 | zone_private_key, |
336 | rvalue, | 332 | entry->rvalue, |
337 | record_count, | 333 | entry->record_count, |
338 | record_data_b64, | 334 | record_data_b64, |
339 | entry->label); | 335 | entry->label); |
340 | |||
341 | GNUNET_free (rvalue); | ||
342 | GNUNET_free (record_count); | ||
343 | GNUNET_free (record_data_b64); | 336 | GNUNET_free (record_data_b64); |
337 | GNUNET_free (zone_private_key); | ||
344 | 338 | ||
345 | GNUNET_DISK_file_write (fh, | 339 | GNUNET_DISK_file_write (fh, |
346 | line, | 340 | line, |