1#include <Windows.h>
2#include <stdio.h>
3#include <sanitizer/allocator_interface.h>
4#include <psapi.h>
5
6// RUN: %clang_cl_asan %Od %s %Fe%t
7// RUN: %t
8// REQUIRES: asan-64-bits
9
10size_t GetRSS() {
11 PROCESS_MEMORY_COUNTERS counters;
12 if (!GetProcessMemoryInfo(GetCurrentProcess(), &counters, sizeof(counters)))
13 return 0;
14 return counters.WorkingSetSize;
15}
16
17int main(){
18 for (int i = 0; i < 1000; i++) {
19 void* a = malloc(1000);
20 free(a);
21 }
22 size_t rss_pre = GetRSS();
23 __sanitizer_purge_allocator();
24 size_t rss_post = GetRSS();
25
26 if (rss_pre <= rss_post){
27 return -1;
28 }
29
30 return 0;
31}
32

source code of compiler-rt/test/asan/TestCases/Windows/sanitizer_purge.cpp