@@ -64,6 +64,8 @@ typedef struct
64
64
65
65
BSON_STATIC_ASSERT (sizeof (mongoc_counters_t ) == 64 );
66
66
67
+ static void * gCounterFallback = NULL ;
68
+
67
69
68
70
#define COUNTER (ident , Category , Name , Description ) \
69
71
mongoc_counter_t __mongoc_counter_##ident;
@@ -122,25 +124,23 @@ mongoc_counters_calc_size (void)
122
124
*
123
125
* Removes the shared memory segment for the current processes counters.
124
126
*/
125
- #ifdef BSON_OS_UNIX
126
127
static void
127
128
mongoc_counters_destroy (void )
128
129
{
129
- char name [32 ];
130
- int pid ;
131
-
132
- pid = getpid ();
133
- bson_snprintf (name , sizeof name , "/mongoc-%u" , pid );
134
- shm_unlink (name );
135
- }
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
- }
130
+ if (gCounterFallback ) {
131
+ bson_free (gCounterFallback );
132
+ gCounterFallback = NULL ;
133
+ #ifndef _WIN32
134
+ } else {
135
+ char name [32 ];
136
+ int pid ;
137
+
138
+ pid = getpid ();
139
+ bson_snprintf (name , sizeof name , "/mongoc-%u" , pid );
140
+ shm_unlink (name );
143
141
#endif
142
+ }
143
+ }
144
144
145
145
146
146
/**
@@ -200,9 +200,10 @@ mongoc_counters_alloc (size_t size)
200
200
use_malloc :
201
201
#endif
202
202
203
- mongoc_counters_memory = bson_malloc0 (size );
203
+ gCounterFallback = bson_malloc0 (size );
204
204
atexit (mongoc_counters_destroy );
205
- return mongoc_counters_memory ;
205
+
206
+ return gCounterFallback ;
206
207
}
207
208
208
209
0 commit comments