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

Commit 20d18966 authored by George Burgess IV's avatar George Burgess IV
Browse files

media: Silence an analyzer complaint; clean up code

The static analyzer is complaining about a memory leak when we create
this unique pointer. This appears to just be a case of the analyzer not
properly modelling returned temporaries.

While I'm in the area, unique_ptr<T, decltype(free)> is generally an
antipattern: if we instead use an empty struct with an attached
operator(), the unique_ptr shrinks to sizeof(void *) bytes (instead of
sizeof(void *) * 2), and the compiler no longer has to indirectly call
free().

As luck would have it, this small refactor makes the analyzer stop
complaining about this code.

Bug: None
Test: Ran the static analyzer. It's happier, and this builds.
Change-Id: I0c98860e2169ceb8e9d21e577cad89d1ef2c6ff9
parent 0544b1ac
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -135,7 +135,7 @@ JNIAudioAttributeHelper::UniqueAaPtr JNIAudioAttributeHelper::makeUnique()
{
    audio_attributes_t *aa = new (calloc(1, sizeof(audio_attributes_t)))
                audio_attributes_t{AUDIO_ATTRIBUTES_INITIALIZER};
    return UniqueAaPtr{aa, free};
    return UniqueAaPtr{aa};
}

jint JNIAudioAttributeHelper::nativeFromJava(JNIEnv* env, jobject jAudioAttributes,
+5 −1
Original line number Diff line number Diff line
@@ -27,7 +27,11 @@ namespace android {
class JNIAudioAttributeHelper
{
public:
    using UniqueAaPtr = std::unique_ptr<audio_attributes_t, decltype(free)*>;
    struct FreeDeleter {
        void operator()(void *p) const { ::free(p); }
    };

    using UniqueAaPtr = std::unique_ptr<audio_attributes_t, FreeDeleter>;

    /**
     * @brief makeUnique helper to prevent leak