Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 40cbbae8 authored by Phil Burk's avatar Phil Burk
Browse files

aaudio: fix warning for use after free

The compiler was complaining because a pointer was printed after it was
freed. The compiler folks agree this is OK and recommended a technique that
prevents the warning.

Test: any AAudio program, look at log for close
Change-Id: I49c005b48edc4a5dcb5c85da2a9e875befc37206
parent ceedc87e
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@
//#define LOG_NDEBUG 0
#include <utils/Log.h>

#include <inttypes.h>
#include <mutex>
#include <time.h>
#include <pthread.h>
@@ -250,10 +251,14 @@ AAUDIO_API aaudio_result_t AAudioStream_close(AAudioStream* stream)
            audioStream->unregisterPlayerBase();
            delete audioStream;
        } else {
            ALOGW("%s attempt to close failed. Close from another thread.", __func__);
            ALOGW("%s attempt to close failed. Close it from another thread.", __func__);
        }
    }
    ALOGD("AAudioStream_close(%p) returned %d ---------", stream, result);
    // We're potentially freeing `stream` above, so its use here makes some
    // static analysis tools unhappy. Casting to uintptr_t helps assure
    // said tools that we're not doing anything bad here.
    ALOGD("AAudioStream_close(%#" PRIxPTR ") returned %d ---------",
          reinterpret_cast<uintptr_t>(stream), result);
    return result;
}