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 9d8cae7b2a
commit 3f5caf2fcb

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);
}
}