< prev index next >
src/java.desktop/unix/native/common/awt/fontpath.c
Print this page
rev 56159 : 8230480: check malloc/calloc results in java.desktop
*** 339,348 ****
--- 339,351 ----
* Hopefully we are left only with Type1 and TrueType directories.
* It doesn't matter much if there are extraneous directories, it'll just
* 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] != '/') {
continue;
}
*** 418,427 ****
--- 421,433 ----
ptr = p3;
while (*ptr++ != NULL) len3++;
}
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) {
continue;
}
*** 814,823 ****
--- 820,833 ----
if (fontSet == NULL) {
/* FcFontList() may return NULL if fonts are not installed. */
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;
if ((*FcPatternGetString)(fontSet->fonts[f], FC_FILE, 0, &file) ==
FcResultMatch) {
*** 838,847 ****
--- 848,858 ----
}
/* Free fontset if one was returned */
(*FcFontSetDestroy)(fontSet);
}
+ cleanup:
/* Free memory and close the ".so" */
(*FcPatternDestroy)(pattern);
closeFontConfig(libfontconfig, JNI_TRUE);
return fontdirs;
}
< prev index next >