summaryrefslogtreecommitdiff
path: root/rs/java/android/renderscript/Allocation.java
diff options
context:
space:
mode:
authorYang Ni <yangni@google.com>2016-03-24 09:40:32 -0700
committerYang Ni <yangni@google.com>2016-03-31 15:57:23 -0700
commit6484b6be5ca5233614d0a8991a5d909543824fc7 (patch)
tree06304c2a22459faa82c45620cee310f55af143f1 /rs/java/android/renderscript/Allocation.java
parent15d4b5aae852f4c4df9b4a97d86fb4e304cfd677 (diff)
Added CloseGuard for BaseObj
Bug: 27719830 To turn on warnings, apps have to add to their Activity.onCreate() method the following code. StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder() .detectLeakedClosableObjects() .penaltyLog() .build()); For Slang generated ScriptC derived classes, we assume their constructors won't throw exceptions after calling the ScriptC constructor. In addition, ScriptIntrinsic derived classes do not seem to throw exceptions in their constructors either. Therefore, we can leave the guard.open() call in the Script constructor. This may be only an approximation, but allows us to add CloseGuard for script objects without making changes to slang. Change-Id: I77ed45239a60b85af5c811dee6c124fb53da9060 (cherry picked from commit eb4dd08ec132f83745b8b28fa7da58eb4478b5b9)
Diffstat (limited to 'rs/java/android/renderscript/Allocation.java')
-rw-r--r--rs/java/android/renderscript/Allocation.java2
1 files changed, 2 insertions, 0 deletions
diff --git a/rs/java/android/renderscript/Allocation.java b/rs/java/android/renderscript/Allocation.java
index fc9296674d89..3dd0a7610fc0 100644
--- a/rs/java/android/renderscript/Allocation.java
+++ b/rs/java/android/renderscript/Allocation.java
@@ -372,6 +372,7 @@ public class Allocation extends BaseObj {
Log.e(RenderScript.LOG_TAG, "Couldn't invoke registerNativeAllocation:" + e);
throw new RSRuntimeException("Couldn't invoke registerNativeAllocation:" + e);
}
+ guard.open("destroy");
}
Allocation(long id, RenderScript rs, Type t, int usage, MipmapControl mips) {
@@ -1907,6 +1908,7 @@ public class Allocation extends BaseObj {
if (type.getID(rs) == 0) {
throw new RSInvalidStateException("Bad Type");
}
+ // TODO: What if there is an exception after this? The native allocation would leak.
long id = rs.nAllocationCreateTyped(type.getID(rs), mips.mID, usage, 0);
if (id == 0) {
throw new RSRuntimeException("Allocation creation failed.");