Skip to content

Commit b2644d1

Browse files
committed
Merge pull request #21 from watsonsong/master
Memory leak fix on windows platform
2 parents ac37cee + 3e3bef5 commit b2644d1

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/mongoc/mongoc-counters.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,13 @@ mongoc_counters_destroy (void)
133133
bson_snprintf (name, sizeof name, "/mongoc-%u", pid);
134134
shm_unlink (name);
135135
}
136+
#else
137+
static void * mongoc_counters_memory = NULL;
138+
static void
139+
mongoc_counters_destroy (void)
140+
{
141+
bson_free(mongoc_counters_memory);
142+
}
136143
#endif
137144

138145

@@ -193,7 +200,9 @@ mongoc_counters_alloc (size_t size)
193200
use_malloc:
194201
#endif
195202

196-
return bson_malloc0(size);
203+
mongoc_counters_memory = bson_malloc0(size);
204+
atexit(mongoc_counters_destroy);
205+
return mongoc_counters_memory;
197206
}
198207

199208

0 commit comments

Comments
 (0)