Merge "liblogcat: avoid double close."

am: 76ecdd6a95

Change-Id: I00e92081207181bd836499fc3c84279ad15a50a0
This commit is contained in:
Josh Gao 2017-10-20 02:13:47 +00:00 committed by android-build-merger
commit e79d41bf0b
2 changed files with 9 additions and 5 deletions

View file

@ -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;
}

View file

@ -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;
}