src/java.desktop/unix/native/common/awt/fontpath.c
branchdatagramsocketimpl-branch
changeset 58678 9cf78a70fa4f
parent 51120 dccdf51b10dd
child 58679 9c3209ff7550
--- a/src/java.desktop/unix/native/common/awt/fontpath.c	Thu Oct 17 20:27:44 2019 +0100
+++ b/src/java.desktop/unix/native/common/awt/fontpath.c	Thu Oct 17 20:53:35 2019 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -341,6 +341,9 @@
      * cost us a little wasted effort upstream.
      */
     fontdirs = (char**)calloc(nPaths+1, sizeof(char*));
+    if (fontdirs == NULL) {
+        return NULL;
+    }
     pos = 0;
     for (i=0; i < nPaths; i++) {
         if (x11Path[i][0] != '/') {
@@ -420,6 +423,9 @@
     }
     totalLen = len1+len2+len3;
     fontdirs = (char**)calloc(totalLen, sizeof(char*));
+    if (fontdirs == NULL) {
+        return NULL;
+    }
 
     for (i=0; i < len1; i++) {
         if (noType1 && strstr(p1[i], "Type1") != NULL) {
@@ -816,6 +822,10 @@
         fontdirs = NULL;
     } else {
         fontdirs = (char**)calloc(fontSet->nfont+1, sizeof(char*));
+        if (fontdirs == NULL) {
+            (*FcFontSetDestroy)(fontSet);
+            goto cleanup;
+        }
         for (f=0; f < fontSet->nfont; f++) {
             FcChar8 *file;
             FcChar8 *dir;
@@ -840,6 +850,7 @@
         (*FcFontSetDestroy)(fontSet);
     }
 
+cleanup:
     /* Free memory and close the ".so" */
     (*FcPatternDestroy)(pattern);
     closeFontConfig(libfontconfig, JNI_TRUE);
@@ -887,9 +898,9 @@
     locale = (*env)->GetStringUTFChars(env, localeStr, 0);
 
     if ((libfontconfig = openFontConfig()) == NULL) {
-        (*env)->ReleaseStringUTFChars (env, fcNameStr, (const char*)fcName);
+        (*env)->ReleaseStringUTFChars(env, fcNameStr, (const char*)fcName);
         if (locale) {
-            (*env)->ReleaseStringUTFChars (env, localeStr,(const char*)locale);
+            (*env)->ReleaseStringUTFChars(env, localeStr,(const char*)locale);
         }
         return -1;
     }
@@ -918,9 +929,9 @@
         FcPatternGetInteger  == NULL ||
         FcPatternDestroy     == NULL) { /* problem with the library: return. */
 
-        (*env)->ReleaseStringUTFChars (env, fcNameStr, (const char*)fcName);
+        (*env)->ReleaseStringUTFChars(env, fcNameStr, (const char*)fcName);
         if (locale) {
-            (*env)->ReleaseStringUTFChars (env, localeStr,(const char*)locale);
+            (*env)->ReleaseStringUTFChars(env, localeStr,(const char*)locale);
         }
         closeFontConfig(libfontconfig, JNI_FALSE);
         return -1;
@@ -945,9 +956,9 @@
     }
     (*FcPatternDestroy)(pattern);
 
-    (*env)->ReleaseStringUTFChars (env, fcNameStr, (const char*)fcName);
+    (*env)->ReleaseStringUTFChars(env, fcNameStr, (const char*)fcName);
     if (locale) {
-        (*env)->ReleaseStringUTFChars (env, localeStr, (const char*)locale);
+        (*env)->ReleaseStringUTFChars(env, localeStr, (const char*)locale);
     }
     closeFontConfig(libfontconfig, JNI_TRUE);
 
@@ -1179,6 +1190,9 @@
         (*env)->DeleteLocalRef(env, fcNameStr);
         if (pattern == NULL) {
             closeFontConfig(libfontconfig, JNI_FALSE);
+            if (locale) {
+                (*env)->ReleaseStringUTFChars(env, localeStr, (const char*)locale);
+            }
             return;
         }
 
@@ -1196,6 +1210,9 @@
         if (fontset == NULL) {
             (*FcPatternDestroy)(pattern);
             closeFontConfig(libfontconfig, JNI_FALSE);
+            if (locale) {
+                (*env)->ReleaseStringUTFChars(env, localeStr, (const char*)locale);
+            }
             return;
         }
 
@@ -1227,6 +1244,9 @@
             (*FcPatternDestroy)(pattern);
             (*FcFontSetDestroy)(fontset);
             closeFontConfig(libfontconfig, JNI_FALSE);
+            if (locale) {
+                (*env)->ReleaseStringUTFChars(env, localeStr, (const char*)locale);
+            }
             return;
         }
         fontCount = 0;
@@ -1269,6 +1289,9 @@
                 (*FcPatternDestroy)(pattern);
                 (*FcFontSetDestroy)(fontset);
                 closeFontConfig(libfontconfig, JNI_FALSE);
+                if (locale) {
+                    (*env)->ReleaseStringUTFChars(env, localeStr, (const char*)locale);
+                }
                 return;
             }
 
@@ -1323,6 +1346,9 @@
                 (*FcPatternDestroy)(pattern);
                 (*FcFontSetDestroy)(fontset);
                 closeFontConfig(libfontconfig, JNI_FALSE);
+                if (locale) {
+                    (*env)->ReleaseStringUTFChars(env, localeStr, (const char*)locale);
+                }
                 return;
             }
             (*env)->SetObjectField(env,fcCompFontObj, fcAllFontsID, fcFontArr);
@@ -1384,7 +1410,7 @@
     /* release resources and close the ".so" */
 
     if (locale) {
-        (*env)->ReleaseStringUTFChars (env, localeStr, (const char*)locale);
+        (*env)->ReleaseStringUTFChars(env, localeStr, (const char*)locale);
     }
     closeFontConfig(libfontconfig, JNI_TRUE);
 }