Skip to content

Commit f0baba8

Browse files
authored
Use struct mallinfo when __GLIBC__ is defined (#14958)
Struct mallinfo is not available with musl libc. Work around the issue by building source code that uses mallinfo only when __GLIBC__ is defined. Fixes #9906.
1 parent 87d1d3e commit f0baba8

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/platform/Linux/DiagnosticDataProviderImpl.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -218,28 +218,39 @@ DiagnosticDataProviderImpl & DiagnosticDataProviderImpl::GetDefaultInstance()
218218

219219
CHIP_ERROR DiagnosticDataProviderImpl::GetCurrentHeapFree(uint64_t & currentHeapFree)
220220
{
221+
#ifndef __GLIBC__
222+
return CHIP_ERROR_NOT_IMPLEMENTED;
223+
#else
221224
struct mallinfo mallocInfo = mallinfo();
222225

223226
// Get the current amount of heap memory, in bytes, that are not being utilized
224227
// by the current running program.
225228
currentHeapFree = mallocInfo.fordblks;
226229

227230
return CHIP_NO_ERROR;
231+
#endif
228232
}
229233

230234
CHIP_ERROR DiagnosticDataProviderImpl::GetCurrentHeapUsed(uint64_t & currentHeapUsed)
231235
{
236+
#ifndef __GLIBC__
237+
return CHIP_ERROR_NOT_IMPLEMENTED;
238+
#else
232239
struct mallinfo mallocInfo = mallinfo();
233240

234241
// Get the current amount of heap memory, in bytes, that are being used by
235242
// the current running program.
236243
currentHeapUsed = mallocInfo.uordblks;
237244

238245
return CHIP_NO_ERROR;
246+
#endif
239247
}
240248

241249
CHIP_ERROR DiagnosticDataProviderImpl::GetCurrentHeapHighWatermark(uint64_t & currentHeapHighWatermark)
242250
{
251+
#ifndef __GLIBC__
252+
return CHIP_ERROR_NOT_IMPLEMENTED;
253+
#else
243254
struct mallinfo mallocInfo = mallinfo();
244255

245256
// The usecase of this function is embedded devices,on which we would need to intercept
@@ -252,6 +263,7 @@ CHIP_ERROR DiagnosticDataProviderImpl::GetCurrentHeapHighWatermark(uint64_t & cu
252263
currentHeapHighWatermark = mallocInfo.uordblks;
253264

254265
return CHIP_NO_ERROR;
266+
#endif
255267
}
256268

257269
CHIP_ERROR DiagnosticDataProviderImpl::GetThreadMetrics(ThreadMetrics ** threadMetricsOut)

0 commit comments

Comments
 (0)