Bug 751262 - Guard against leaking memory if NewDirectByteBuffer fails. r=blassey

This commit is contained in:
Kartikaya Gupta 2012-05-10 13:15:56 -04:00
parent 525e463364
commit 2f23696854

View File

@ -66,7 +66,14 @@ __attribute__ ((visibility("default")))
jobject JNICALL
Java_org_mozilla_gecko_GeckoAppShell_allocateDirectBuffer(JNIEnv *jenv, jclass, jlong size)
{
return jenv->NewDirectByteBuffer(malloc(size), size);
jobject buffer = NULL;
void* mem = malloc(size);
if (mem) {
buffer = jenv->NewDirectByteBuffer(mem, size);
if (!buffer)
free(mem);
}
return buffer;
}
extern "C"
@ -107,4 +114,4 @@ Java_org_mozilla_gecko_GeckoAppShell_unlockDatabaseFile(JNIEnv *jenv, jclass, js
}
close(fd);
}
}