diff options
| -rw-r--r-- | src/org/openintents/openpgp/util/OpenPgpApi.java | 21 | 
1 files changed, 14 insertions, 7 deletions
| diff --git a/src/org/openintents/openpgp/util/OpenPgpApi.java b/src/org/openintents/openpgp/util/OpenPgpApi.java index 589b514..9f51851 100644 --- a/src/org/openintents/openpgp/util/OpenPgpApi.java +++ b/src/org/openintents/openpgp/util/OpenPgpApi.java @@ -27,6 +27,7 @@ import android.util.Log;  import org.openintents.openpgp.IOpenPgpService;  import org.openintents.openpgp.OpenPgpError; +import java.io.IOException;  import java.io.InputStream;  import java.io.OutputStream; @@ -291,13 +292,15 @@ public class OpenPgpApi {      }      public Intent executeApi(Intent data, InputStream is, OutputStream os) { +        ParcelFileDescriptor input = null; +        ParcelFileDescriptor output = null;          try { +            // always send version from client              data.putExtra(EXTRA_API_VERSION, OpenPgpApi.API_VERSION);              Intent result;              // pipe the input and output -            ParcelFileDescriptor input = null;              if (is != null) {                  input = ParcelFileDescriptorUtil.pipeFrom(is,                          new ParcelFileDescriptorUtil.IThreadListener() { @@ -309,7 +312,6 @@ public class OpenPgpApi {                          }                  );              } -            ParcelFileDescriptor output = null;              if (os != null) {                  output = ParcelFileDescriptorUtil.pipeTo(os,                          new ParcelFileDescriptorUtil.IThreadListener() { @@ -324,11 +326,6 @@ public class OpenPgpApi {              // blocks until result is ready              result = mService.execute(data, input, output); -            // close() is required to halt the TransferThread -            if (output != null) { -                output.close(); -            } -            // TODO: close input?              // set class loader to current context to allow unparcelling              // of OpenPgpError and OpenPgpSignatureResult @@ -343,6 +340,16 @@ public class OpenPgpApi {              result.putExtra(RESULT_ERROR,                      new OpenPgpError(OpenPgpError.CLIENT_SIDE_ERROR, e.getMessage()));              return result; +        } finally { +            // close() is required to halt the TransferThread +            if (output != null) { +                try { +                    output.close(); +                } catch (IOException e) { +                    Log.e(OpenPgpApi.TAG, "IOException when closing ParcelFileDescriptor!", e); +                } +            } +            // TODO: close input? Maybe the client wants to still use the input stream          }      } | 
