length = (*env)->GetStringLength (env, string);
buffer = malloc (length * sizeof *buffer);
+
+ /* Out of memory. */
+ if (!buffer)
+ return 0;
+
characters = (*env)->GetStringChars (env, string, NULL);
if (!characters)
length = (*env)->GetStringLength (env, string);
buffer = malloc (length * sizeof *buffer);
+
+ /* Out of memory. */
+ if (!buffer)
+ return 0;
+
characters = (*env)->GetStringChars (env, string, NULL);
if (!characters)