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

Commit 76ecdd6a authored by Josh Gao's avatar Josh Gao Committed by Gerrit Code Review
Browse files

Merge "liblogcat: avoid double close."

parents cba7f571 03d055d6
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -1831,11 +1831,10 @@ int android_logcat_destroy(android_logcat_context* ctx) {
    }
    android::close_output(context);
    android::close_error(context);

    if (context->fds[1] >= 0) {
        // NB: could be closed by the above fclose(s), ignore error.
        int save_errno = errno;
        // NB: this should be closed by close_output, but just in case...
        close(context->fds[1]);
        errno = save_errno;
        context->fds[1] = -1;
    }

+7 −2
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
 */

#include <ctype.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
@@ -98,8 +99,12 @@ FILE* android_logcat_popen(android_logcat_context* ctx, const char* command) {
        return NULL;
    }

    FILE* retval = fdopen(fd, "reb");
    if (!retval) android_logcat_destroy(ctx);
    int duped = dup(fd);
    FILE* retval = fdopen(duped, "reb");
    if (!retval) {
        close(duped);
        android_logcat_destroy(ctx);
    }
    return retval;
}