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

Commit 53f35f77 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "[statsd] Fix a memory leak"

parents 7e39d38e ef8262ce
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -29,6 +29,8 @@
#include <utils/Looper.h>
#include <utils/StrongPointer.h>

#include <memory>

#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
@@ -72,7 +74,7 @@ static status_t start_log_reader_thread(const sp<StatsService>& service) {
    pthread_t thread;

    // Thread data.
    log_reader_thread_data* data = new log_reader_thread_data();
    std::unique_ptr<log_reader_thread_data> data = std::make_unique<log_reader_thread_data>();
    data->service = service;

    // Create the thread
@@ -86,11 +88,15 @@ static status_t start_log_reader_thread(const sp<StatsService>& service) {
        pthread_attr_destroy(&attr);
        return err;
    }
    err = pthread_create(&thread, &attr, log_reader_thread_func, static_cast<void*>(data));
    err = pthread_create(&thread, &attr, log_reader_thread_func,
                         static_cast<void*>(data.get()));
    if (err != NO_ERROR) {
        pthread_attr_destroy(&attr);
        return err;
    }
    // Release here rather than in pthread_create, since an error creating the
    // thread leaves `data` ownerless.
    data.release();
    pthread_attr_destroy(&attr);

    return NO_ERROR;