Skip to content

Commit c3d9fb6

Browse files
authored
Merge pull request #7444 from miyazakh/trackmem_exclusion
Exclusively tracking mem properties
2 parents eb12585 + dab6726 commit c3d9fb6

1 file changed

Lines changed: 26 additions & 19 deletions

File tree

wolfssl/wolfcrypt/mem_track.h

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -177,30 +177,34 @@ static WC_INLINE void* TrackMalloc(size_t sz)
177177
(void)line;
178178
#endif
179179
#endif
180+
#if defined(DO_MEM_LIST) || defined(DO_MEM_STATS)
181+
if (pthread_mutex_lock(&memLock) == 0)
182+
{
183+
#endif
180184

181185
#ifdef DO_MEM_STATS
182-
ourMemStats.totalAllocs++;
183-
ourMemStats.totalBytes += sz;
184-
ourMemStats.currentBytes += sz;
185-
#ifdef WOLFSSL_TRACK_MEMORY_VERBOSE
186-
if (ourMemStats.peakAllocsTripOdometer < ourMemStats.totalAllocs -
187-
ourMemStats.totalDeallocs) {
188-
ourMemStats.peakAllocsTripOdometer = ourMemStats.totalAllocs -
189-
ourMemStats.totalDeallocs;
190-
}
191-
if (ourMemStats.peakBytesTripOdometer < ourMemStats.currentBytes)
192-
#endif
193-
{
186+
ourMemStats.totalAllocs++;
187+
ourMemStats.totalBytes += sz;
188+
ourMemStats.currentBytes += sz;
194189
#ifdef WOLFSSL_TRACK_MEMORY_VERBOSE
195-
ourMemStats.peakBytesTripOdometer = ourMemStats.currentBytes;
190+
if (ourMemStats.peakAllocsTripOdometer < ourMemStats.totalAllocs -
191+
ourMemStats.totalDeallocs) {
192+
ourMemStats.peakAllocsTripOdometer = ourMemStats.totalAllocs -
193+
ourMemStats.totalDeallocs;
194+
}
195+
if (ourMemStats.peakBytesTripOdometer < ourMemStats.currentBytes)
196196
#endif
197-
if (ourMemStats.currentBytes > ourMemStats.peakBytes)
198-
ourMemStats.peakBytes = ourMemStats.currentBytes;
199-
}
197+
{
198+
#ifdef WOLFSSL_TRACK_MEMORY_VERBOSE
199+
ourMemStats.peakBytesTripOdometer = ourMemStats.currentBytes;
200+
#endif
201+
if (ourMemStats.currentBytes > ourMemStats.peakBytes)
202+
ourMemStats.peakBytes = ourMemStats.currentBytes;
203+
}
204+
200205
#endif /* DO_MEM_STATS */
201206

202207
#ifdef DO_MEM_LIST
203-
if (pthread_mutex_lock(&memLock) == 0) {
204208
#ifdef WOLFSSL_DEBUG_MEMORY
205209
header->func = func;
206210
header->line = line;
@@ -218,7 +222,8 @@ static WC_INLINE void* TrackMalloc(size_t sz)
218222
}
219223
ourMemList.tail = header; /* add to the end either way */
220224
ourMemList.count++;
221-
225+
#endif
226+
#if defined(DO_MEM_LIST) || defined(DO_MEM_STATS)
222227
pthread_mutex_unlock(&memLock);
223228
}
224229
#endif /* DO_MEM_LIST */
@@ -245,7 +250,7 @@ static WC_INLINE void TrackFree(void* ptr)
245250
header = &mt->u.hint;
246251
sz = header->thisSize;
247252

248-
#ifdef DO_MEM_LIST
253+
#if defined(DO_MEM_LIST) || defined(DO_MEM_STATS)
249254
if (pthread_mutex_lock(&memLock) == 0)
250255
{
251256
#endif
@@ -277,7 +282,9 @@ static WC_INLINE void TrackFree(void* ptr)
277282
prev->next = next;
278283
}
279284
ourMemList.count--;
285+
#endif
280286

287+
#if defined(DO_MEM_LIST) || defined(DO_MEM_STATS)
281288
pthread_mutex_unlock(&memLock);
282289
}
283290
#endif

0 commit comments

Comments
 (0)