Destroy map iterators once we're done with them.

Each call to enif_map_iterator_create() must be paired with a call to
enif_map_iterator_destroy(). Otherwise, we'll leak memory.

Fixes #112


Project: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/commit/fa825b6f
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/tree/fa825b6f
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/diff/fa825b6f

Branch: refs/heads/master
Commit: fa825b6fd6ca9518b090edc055d1413b8a44068d
Parents: cfc61a2
Author: Jon Parise <[email protected]>
Authored: Wed Nov 25 17:58:00 2015 -0500
Committer: Jon Parise <[email protected]>
Committed: Wed Nov 25 18:23:37 2015 -0500

----------------------------------------------------------------------
 c_src/encoder.c | 3 +++
 1 file changed, 3 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/blob/fa825b6f/c_src/encoder.c
----------------------------------------------------------------------
diff --git a/c_src/encoder.c b/c_src/encoder.c
index 4a96048..0029086 100644
--- a/c_src/encoder.c
+++ b/c_src/encoder.c
@@ -559,6 +559,7 @@ enc_map_to_ejson(ErlNifEnv* env, ERL_NIF_TERM map, 
ERL_NIF_TERM* out)
 
     do {
         if(!enif_map_iterator_get_pair(env, &iter, &key, &val)) {
+            enif_map_iterator_destroy(env, &iter);
             fprintf(stderr, "bad get pair\r\n");
             return 0;
         }
@@ -566,6 +567,8 @@ enc_map_to_ejson(ErlNifEnv* env, ERL_NIF_TERM map, 
ERL_NIF_TERM* out)
         list = enif_make_list_cell(env, tuple, list);
     } while(enif_map_iterator_next(env, &iter));
 
+    enif_map_iterator_destroy(env, &iter);
+
     *out = enif_make_tuple1(env, list);
     return 1;
 }

Reply via email to