Merge "liblogcat: avoid double close."
am: 76ecdd6a95
Change-Id: I00e92081207181bd836499fc3c84279ad15a50a0
This commit is contained in:
commit
e79d41bf0b
2 changed files with 9 additions and 5 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue