Work around changes in newer versions of glibc
[model-checker.git] / mymemory.cc
index 4182e094e5251c1a8efedbe8a92c232c012f13f3..e8ec08050f5d8e5389c01e136fe1c0a27f374f13 100644 (file)
@@ -16,6 +16,7 @@
 size_t allocatedReqs[REQUESTS_BEFORE_ALLOC] = { 0 };
 int nextRequest = 0;
 int howManyFreed = 0;
+int switch_alloc = 0;
 #if !USE_MPROTECT_SNAPSHOT
 static mspace sStaticSpace = NULL;
 #endif
@@ -179,6 +180,9 @@ static void * user_malloc(size_t size)
 void *malloc(size_t size)
 {
        if (user_snapshot_space) {
+               if (switch_alloc) {
+                       return model_malloc(size);
+               }
                /* Only perform user allocations from user context */
                ASSERT(!model || thread_current());
                return user_malloc(size);
@@ -189,8 +193,12 @@ void *malloc(size_t size)
 /** @brief Snapshotting free implementation for user programs */
 void free(void * ptr)
 {
-       if (!DontFree(ptr))
+       if (!DontFree(ptr)) {
+               if (switch_alloc) {
+                       return model_free(ptr);
+               }
                mspace_free(user_snapshot_space, ptr);
+       }
 }
 
 /** @brief Snapshotting realloc implementation for user programs */