From de83fdf8060a4a75484a37b5fa1bb71e64852d1e Mon Sep 17 00:00:00 2001 From: dswitkin Date: Thu, 6 Nov 2008 19:55:38 +0000 Subject: [PATCH] Fixed two leaks when using AndroidHttpClient. git-svn-id: https://zxing.googlecode.com/svn/trunk@675 59b500cc-1b3d-0410-9834-0bbf25fbcc57 --- .../src/com/google/zxing/client/android/QRCodeEncoder.java | 7 ++++++- .../zxing/client/android/SearchBookContentsActivity.java | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/android/src/com/google/zxing/client/android/QRCodeEncoder.java b/android/src/com/google/zxing/client/android/QRCodeEncoder.java index 953b08d03..04bca1101 100755 --- a/android/src/com/google/zxing/client/android/QRCodeEncoder.java +++ b/android/src/com/google/zxing/client/android/QRCodeEncoder.java @@ -160,10 +160,11 @@ public class QRCodeEncoder { public void run() { String url = CHART_SERVER_URL + mPixelResolution + "x" + mPixelResolution + "&chl=" + mContents; + AndroidHttpClient client = null; try { URI uri = new URI("http", url, null); HttpGet get = new HttpGet(uri); - AndroidHttpClient client = AndroidHttpClient.newInstance(mUserAgent); + client = AndroidHttpClient.newInstance(mUserAgent); HttpResponse response = client.execute(get); HttpEntity entity = response.getEntity(); Bitmap image = BitmapFactory.decodeStream(entity.getContent()); @@ -180,6 +181,10 @@ public class QRCodeEncoder { Log.e(TAG, e.toString()); Message message = Message.obtain(mHandler, R.id.encode_failed); message.sendToTarget(); + } finally { + if (client != null) { + client.close(); + } } } } diff --git a/android/src/com/google/zxing/client/android/SearchBookContentsActivity.java b/android/src/com/google/zxing/client/android/SearchBookContentsActivity.java index c1e41c044..f67687813 100644 --- a/android/src/com/google/zxing/client/android/SearchBookContentsActivity.java +++ b/android/src/com/google/zxing/client/android/SearchBookContentsActivity.java @@ -294,6 +294,7 @@ public class SearchBookContentsActivity extends Activity { } catch (IOException e) { Log.e(TAG, e.toString()); } + client.close(); } return cookie; }