You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@avro.apache.org by dc...@apache.org on 2012/05/20 16:02:53 UTC

svn commit: r1340724 - in /avro/trunk: CHANGES.txt lang/c/src/datafile.c lang/c/src/datum.c lang/c/src/map.c

Author: dcreager
Date: Sun May 20 14:02:53 2012
New Revision: 1340724

URL: http://svn.apache.org/viewvc?rev=1340724&view=rev
Log:
AVRO-1083. C: Fix multiple memory leaks

Contributed by Pugachev Maxim.

Modified:
    avro/trunk/CHANGES.txt
    avro/trunk/lang/c/src/datafile.c
    avro/trunk/lang/c/src/datum.c
    avro/trunk/lang/c/src/map.c

Modified: avro/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/avro/trunk/CHANGES.txt?rev=1340724&r1=1340723&r2=1340724&view=diff
==============================================================================
--- avro/trunk/CHANGES.txt (original)
+++ avro/trunk/CHANGES.txt Sun May 20 14:02:53 2012
@@ -93,6 +93,8 @@ Avro 1.7.0 (unreleased)
     AVRO-1084. C: Fix reference counting in file_reader and file_writer.
     (Pugachev Maxim via dcreager)
 
+    AVRO-1083. C: Fix multiple memory leaks.  (Pugachev Maxim via dcreager)
+
 Avro 1.6.3 (5 March 2012)
 
     AVRO-1077. Missing 'inline' for union set function. (thiru)

Modified: avro/trunk/lang/c/src/datafile.c
URL: http://svn.apache.org/viewvc/avro/trunk/lang/c/src/datafile.c?rev=1340724&r1=1340723&r2=1340724&view=diff
==============================================================================
--- avro/trunk/lang/c/src/datafile.c (original)
+++ avro/trunk/lang/c/src/datafile.c Sun May 20 14:02:53 2012
@@ -197,15 +197,20 @@ int avro_file_writer_create_with_codec(c
 	w->codec = (avro_codec_t) avro_new(struct avro_codec_t_);
 	if (!w->codec) {
 		avro_set_error("Cannot allocate new codec");
+		avro_freet(struct avro_file_writer_t_, w);
 		return ENOMEM;
 	}
 	rval = avro_codec(w->codec, codec);
 	if (rval) {
+		avro_codec_reset(w->codec);
 		avro_freet(struct avro_codec_t_, w->codec);
+		avro_freet(struct avro_file_writer_t_, w);
 		return rval;
 	}
 	rval = file_writer_create(path, schema, w, block_size);
 	if (rval) {
+		avro_codec_reset(w->codec);
+		avro_freet(struct avro_codec_t_, w->codec);
 		avro_freet(struct avro_file_writer_t_, w);
 		return rval;
 	}
@@ -405,6 +410,7 @@ int avro_file_reader_fp(FILE *fp, const 
 	r->block_reader = avro_reader_memory(0, 0);
 	if (!r->block_reader) {
 		avro_set_error("Cannot allocate block reader for file %s", path);
+		avro_reader_free(r->reader);
 		avro_freet(struct avro_file_reader_t_, r);
 		return ENOMEM;
 	}
@@ -412,6 +418,7 @@ int avro_file_reader_fp(FILE *fp, const 
 	r->codec = (avro_codec_t) avro_new(struct avro_codec_t_);
 	if (!r->codec) {
 		avro_set_error("Could not allocate codec for file %s", path);
+		avro_reader_free(r->reader);
 		avro_freet(struct avro_file_reader_t_, r);
 		return ENOMEM;
 	}
@@ -420,6 +427,8 @@ int avro_file_reader_fp(FILE *fp, const 
 				r->sync, sizeof(r->sync));
 	if (rval) {
 		avro_reader_free(r->reader);
+		avro_codec_reset(r->codec);
+		avro_freet(struct avro_codec_t_, r->codec);
 		avro_freet(struct avro_file_reader_t_, r);
 		return rval;
 	}
@@ -430,6 +439,8 @@ int avro_file_reader_fp(FILE *fp, const 
 	rval = file_read_block_count(r);
 	if (rval) {
 		avro_reader_free(r->reader);
+		avro_codec_reset(r->codec);
+		avro_freet(struct avro_codec_t_, r->codec);
 		avro_freet(struct avro_file_reader_t_, r);
 		return rval;
 	}

Modified: avro/trunk/lang/c/src/datum.c
URL: http://svn.apache.org/viewvc/avro/trunk/lang/c/src/datum.c?rev=1340724&r1=1340723&r2=1340724&view=diff
==============================================================================
--- avro/trunk/lang/c/src/datum.c (original)
+++ avro/trunk/lang/c/src/datum.c Sun May 20 14:02:53 2012
@@ -618,6 +618,7 @@ static avro_datum_t avro_fixed_private(a
 	struct avro_fixed_datum_t *datum =
 	    (struct avro_fixed_datum_t *) avro_new(struct avro_fixed_datum_t);
 	if (!datum) {
+		avro_free((char *) bytes, size);
 		avro_set_error("Cannot create new fixed datum");
 		return NULL;
 	}

Modified: avro/trunk/lang/c/src/map.c
URL: http://svn.apache.org/viewvc/avro/trunk/lang/c/src/map.c?rev=1340724&r1=1340723&r2=1340724&view=diff
==============================================================================
--- avro/trunk/lang/c/src/map.c (original)
+++ avro/trunk/lang/c/src/map.c Sun May 20 14:02:53 2012
@@ -113,6 +113,7 @@ int avro_raw_map_get_or_create(avro_raw_
 		st_insert((st_table *) map->indices_by_key,
 			  (st_data_t) raw_entry->key, (st_data_t) i);
 		if (!raw_entry) {
+			avro_str_free((char*)raw_entry->key);
 			return -ENOMEM;
 		}
 		el = ((char *) raw_entry) + sizeof(avro_raw_map_entry_t);