diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2015-01-15 15:33:58 +0900 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2015-01-16 13:18:31 +0100 |
commit | a5e2c361f031e1ce55c4110145a0d1011eba11b3 (patch) | |
tree | af387607907891d7c8d51bba278333ede09f08bb /android | |
parent | 1e4f6eeba42f68d2587700e45ba1362f920174a3 (diff) |
android: guard buffer allocation and return null if alloc. fails
Change-Id: I684c7af245cc755b94f69e175c652d161e0f643a
Diffstat (limited to 'android')
-rw-r--r-- | android/Bootstrap/src/org/libreoffice/kit/DirectBufferAllocator.java | 10 | ||||
-rw-r--r-- | android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java | 6 |
2 files changed, 15 insertions, 1 deletions
diff --git a/android/Bootstrap/src/org/libreoffice/kit/DirectBufferAllocator.java b/android/Bootstrap/src/org/libreoffice/kit/DirectBufferAllocator.java index 0e30e459ff93..670e39724aad 100644 --- a/android/Bootstrap/src/org/libreoffice/kit/DirectBufferAllocator.java +++ b/android/Bootstrap/src/org/libreoffice/kit/DirectBufferAllocator.java @@ -87,4 +87,14 @@ public final class DirectBufferAllocator { // can't free buffer - leave this to the VM return null; } + + public static ByteBuffer guardedAllocate(int size) { + ByteBuffer buffer = null; + try { + buffer = allocate(size); + } catch (OutOfMemoryError oomException) { + return null; + } + return buffer; + } } diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java index 0e2db4b91282..752e0a91ea45 100644 --- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java +++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java @@ -4,6 +4,7 @@ import android.graphics.Bitmap; import android.graphics.RectF; import android.util.Log; +import org.libreoffice.kit.DirectBufferAllocator; import org.libreoffice.kit.Document; import org.libreoffice.kit.LibreOfficeKit; import org.libreoffice.kit.Office; @@ -189,7 +190,10 @@ public class LOKitTileProvider implements TileProvider, Document.MessageCallback @Override public CairoImage createTile(float x, float y, IntSize tileSize, float zoom) { - ByteBuffer buffer = ByteBuffer.allocateDirect(tileSize.width * tileSize.height * 4); + ByteBuffer buffer = DirectBufferAllocator.guardedAllocate(tileSize.width * tileSize.height * 4); + if (buffer == null) + return null; + CairoImage image = new BufferedCairoImage(buffer, tileSize.width, tileSize.height, CairoImage.FORMAT_ARGB32); rerenderTile(image, x, y, tileSize, zoom); return image; |