8230480: check malloc/calloc results in java.desktop
Reviewed-by: rriggs
This commit is contained in:
parent
603689f760
commit
4db0f9cbbb
@ -414,11 +414,18 @@ static void* CreatePortControl(PortMixer *mixer, PortControlCreator *creator, Po
|
|||||||
AudioControl **audioControls, int offset, int len) {
|
AudioControl **audioControls, int offset, int len) {
|
||||||
void *jControl = NULL;
|
void *jControl = NULL;
|
||||||
PortControl *control = (PortControl *)calloc(1, sizeof(PortControl));
|
PortControl *control = (PortControl *)calloc(1, sizeof(PortControl));
|
||||||
|
if (control == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
float precision = 0.01;
|
float precision = 0.01;
|
||||||
|
|
||||||
control->type = type;
|
control->type = type;
|
||||||
control->controlCount = len;
|
control->controlCount = len;
|
||||||
control->audioControls = (AudioControl **)malloc(len * sizeof(AudioControl *));
|
control->audioControls = (AudioControl **)malloc(len * sizeof(AudioControl *));
|
||||||
|
if (control->audioControls == NULL) {
|
||||||
|
free(control);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
memcpy(control->audioControls, audioControls + offset, len * sizeof(AudioControl *));
|
memcpy(control->audioControls, audioControls + offset, len * sizeof(AudioControl *));
|
||||||
|
|
||||||
switch (control->type) {
|
switch (control->type) {
|
||||||
@ -482,6 +489,9 @@ void PORT_GetControls(void* id, INT32 portIndex, PortControlCreator* creator) {
|
|||||||
OS_ERROR1(err, "PORT_GetControls (portIndex = %d) get OwnedObject values", portIndex);
|
OS_ERROR1(err, "PORT_GetControls (portIndex = %d) get OwnedObject values", portIndex);
|
||||||
} else {
|
} else {
|
||||||
mixer->deviceControls = (AudioControl *)calloc(mixer->deviceControlCount, sizeof(AudioControl));
|
mixer->deviceControls = (AudioControl *)calloc(mixer->deviceControlCount, sizeof(AudioControl));
|
||||||
|
if (mixer->deviceControls == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; i < mixer->deviceControlCount; i++) {
|
for (int i = 0; i < mixer->deviceControlCount; i++) {
|
||||||
AudioControl *control = &mixer->deviceControls[i];
|
AudioControl *control = &mixer->deviceControls[i];
|
||||||
@ -615,10 +625,16 @@ void PORT_GetControls(void* id, INT32 portIndex, PortControlCreator* creator) {
|
|||||||
if (err == noErr) {
|
if (err == noErr) {
|
||||||
CFIndex length = CFStringGetLength(cfname) + 1;
|
CFIndex length = CFStringGetLength(cfname) + 1;
|
||||||
channelName = (char *)malloc(length);
|
channelName = (char *)malloc(length);
|
||||||
|
if (channelName == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
CFStringGetCString(cfname, channelName, length, kCFStringEncodingUTF8);
|
CFStringGetCString(cfname, channelName, length, kCFStringEncodingUTF8);
|
||||||
CFRelease(cfname);
|
CFRelease(cfname);
|
||||||
} else {
|
} else {
|
||||||
channelName = (char *)malloc(16);
|
channelName = (char *)malloc(16);
|
||||||
|
if (channelName == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
sprintf(channelName, "Ch %d", ch);
|
sprintf(channelName, "Ch %d", ch);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -402,6 +402,9 @@ awt_allocate_colors(AwtGraphicsConfigDataPtr awt_data)
|
|||||||
pVI = &awt_data->awt_visInfo;
|
pVI = &awt_data->awt_visInfo;
|
||||||
awt_data->awt_num_colors = awt_data->awt_visInfo.colormap_size;
|
awt_data->awt_num_colors = awt_data->awt_visInfo.colormap_size;
|
||||||
awt_data->awtImage = (awtImageData *) calloc (1, sizeof (awtImageData));
|
awt_data->awtImage = (awtImageData *) calloc (1, sizeof (awtImageData));
|
||||||
|
if (awt_data->awtImage == NULL) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
pPFV = XListPixmapFormats(dpy, &numpfv);
|
pPFV = XListPixmapFormats(dpy, &numpfv);
|
||||||
if (pPFV) {
|
if (pPFV) {
|
||||||
@ -572,12 +575,17 @@ awt_allocate_colors(AwtGraphicsConfigDataPtr awt_data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (awt_data->awt_num_colors > paletteSize) {
|
if (awt_data->awt_num_colors > paletteSize) {
|
||||||
free (awt_data->awtImage);
|
free(awt_data->awtImage);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Allocate ColorData structure */
|
/* Allocate ColorData structure */
|
||||||
awt_data->color_data = ZALLOC (_ColorData);
|
awt_data->color_data = ZALLOC (_ColorData);
|
||||||
|
if (awt_data->color_data == NULL) {
|
||||||
|
free(awt_data->awtImage);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
awt_data->color_data->screendata = 1; /* This ColorData struct corresponds
|
awt_data->color_data->screendata = 1; /* This ColorData struct corresponds
|
||||||
to some AWT screen/visual, so when
|
to some AWT screen/visual, so when
|
||||||
any IndexColorModel using this
|
any IndexColorModel using this
|
||||||
@ -594,6 +602,11 @@ awt_allocate_colors(AwtGraphicsConfigDataPtr awt_data)
|
|||||||
|
|
||||||
awt_data->color_data->awt_Colors =
|
awt_data->color_data->awt_Colors =
|
||||||
(ColorEntry *)calloc(paletteSize, sizeof (ColorEntry));
|
(ColorEntry *)calloc(paletteSize, sizeof (ColorEntry));
|
||||||
|
if (awt_data->color_data->awt_Colors == NULL) {
|
||||||
|
free(awt_data->awtImage);
|
||||||
|
free(awt_data->color_data);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
XQueryColors(dpy, cm, cols, awt_data->awt_num_colors);
|
XQueryColors(dpy, cm, cols, awt_data->awt_num_colors);
|
||||||
for (i = 0; i < awt_data->awt_num_colors; i++) {
|
for (i = 0; i < awt_data->awt_num_colors; i++) {
|
||||||
@ -667,6 +680,11 @@ awt_allocate_colors(AwtGraphicsConfigDataPtr awt_data)
|
|||||||
|
|
||||||
awt_data->color_data->img_grays =
|
awt_data->color_data->img_grays =
|
||||||
(unsigned char *)calloc(256, sizeof(unsigned char));
|
(unsigned char *)calloc(256, sizeof(unsigned char));
|
||||||
|
if ( awt_data->color_data->img_grays == NULL) {
|
||||||
|
free(awt_data->awtImage);
|
||||||
|
free(awt_data->color_data);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
for (g = 0; g < 256; g++) {
|
for (g = 0; g < 256; g++) {
|
||||||
int mindist, besti;
|
int mindist, besti;
|
||||||
int d;
|
int d;
|
||||||
@ -810,6 +828,11 @@ awt_allocate_colors(AwtGraphicsConfigDataPtr awt_data)
|
|||||||
awt_data->color_data->img_clr_tbl =
|
awt_data->color_data->img_clr_tbl =
|
||||||
(unsigned char *)calloc(LOOKUPSIZE * LOOKUPSIZE * LOOKUPSIZE,
|
(unsigned char *)calloc(LOOKUPSIZE * LOOKUPSIZE * LOOKUPSIZE,
|
||||||
sizeof(unsigned char));
|
sizeof(unsigned char));
|
||||||
|
if (awt_data->color_data->img_clr_tbl == NULL) {
|
||||||
|
free(awt_data->awtImage);
|
||||||
|
free(awt_data->color_data);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
img_makePalette(cmapsize, k, LOOKUPSIZE, 50, 250,
|
img_makePalette(cmapsize, k, LOOKUPSIZE, 50, 250,
|
||||||
allocatedColorsNum, TRUE, reds, greens, blues,
|
allocatedColorsNum, TRUE, reds, greens, blues,
|
||||||
awt_data->color_data->img_clr_tbl);
|
awt_data->color_data->img_clr_tbl);
|
||||||
@ -858,6 +881,12 @@ awt_allocate_colors(AwtGraphicsConfigDataPtr awt_data)
|
|||||||
awt_data->color_data->awt_icmLUT2Colors =
|
awt_data->color_data->awt_icmLUT2Colors =
|
||||||
(unsigned char *)calloc(paletteSize, sizeof (unsigned char));
|
(unsigned char *)calloc(paletteSize, sizeof (unsigned char));
|
||||||
awt_data->color_data->awt_icmLUT = (int *)calloc(paletteSize, sizeof(int));
|
awt_data->color_data->awt_icmLUT = (int *)calloc(paletteSize, sizeof(int));
|
||||||
|
if (awt_data->color_data->awt_icmLUT2Colors == NULL || awt_data->color_data->awt_icmLUT == NULL) {
|
||||||
|
free(awt_data->awtImage);
|
||||||
|
free(awt_data->color_data);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
for (i=0; i < paletteSize; i++) {
|
for (i=0; i < paletteSize; i++) {
|
||||||
/* Keep the mapping between this lut and the actual cmap */
|
/* Keep the mapping between this lut and the actual cmap */
|
||||||
awt_data->color_data->awt_icmLUT2Colors
|
awt_data->color_data->awt_icmLUT2Colors
|
||||||
|
@ -341,6 +341,9 @@ static char **getX11FontPath ()
|
|||||||
* cost us a little wasted effort upstream.
|
* cost us a little wasted effort upstream.
|
||||||
*/
|
*/
|
||||||
fontdirs = (char**)calloc(nPaths+1, sizeof(char*));
|
fontdirs = (char**)calloc(nPaths+1, sizeof(char*));
|
||||||
|
if (fontdirs == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
pos = 0;
|
pos = 0;
|
||||||
for (i=0; i < nPaths; i++) {
|
for (i=0; i < nPaths; i++) {
|
||||||
if (x11Path[i][0] != '/') {
|
if (x11Path[i][0] != '/') {
|
||||||
@ -420,6 +423,9 @@ static char* mergePaths(char **p1, char **p2, char **p3, jboolean noType1) {
|
|||||||
}
|
}
|
||||||
totalLen = len1+len2+len3;
|
totalLen = len1+len2+len3;
|
||||||
fontdirs = (char**)calloc(totalLen, sizeof(char*));
|
fontdirs = (char**)calloc(totalLen, sizeof(char*));
|
||||||
|
if (fontdirs == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
for (i=0; i < len1; i++) {
|
for (i=0; i < len1; i++) {
|
||||||
if (noType1 && strstr(p1[i], "Type1") != NULL) {
|
if (noType1 && strstr(p1[i], "Type1") != NULL) {
|
||||||
@ -816,6 +822,10 @@ static char **getFontConfigLocations() {
|
|||||||
fontdirs = NULL;
|
fontdirs = NULL;
|
||||||
} else {
|
} else {
|
||||||
fontdirs = (char**)calloc(fontSet->nfont+1, sizeof(char*));
|
fontdirs = (char**)calloc(fontSet->nfont+1, sizeof(char*));
|
||||||
|
if (fontdirs == NULL) {
|
||||||
|
(*FcFontSetDestroy)(fontSet);
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
for (f=0; f < fontSet->nfont; f++) {
|
for (f=0; f < fontSet->nfont; f++) {
|
||||||
FcChar8 *file;
|
FcChar8 *file;
|
||||||
FcChar8 *dir;
|
FcChar8 *dir;
|
||||||
@ -840,6 +850,7 @@ static char **getFontConfigLocations() {
|
|||||||
(*FcFontSetDestroy)(fontSet);
|
(*FcFontSetDestroy)(fontSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cleanup:
|
||||||
/* Free memory and close the ".so" */
|
/* Free memory and close the ".so" */
|
||||||
(*FcPatternDestroy)(pattern);
|
(*FcPatternDestroy)(pattern);
|
||||||
closeFontConfig(libfontconfig, JNI_TRUE);
|
closeFontConfig(libfontconfig, JNI_TRUE);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -66,6 +66,9 @@ static GtkLib** get_libs_order(GtkVersion version) {
|
|||||||
if (!n_libs) {
|
if (!n_libs) {
|
||||||
n_libs = sizeof(gtk_libs) / sizeof(GtkLib);
|
n_libs = sizeof(gtk_libs) / sizeof(GtkLib);
|
||||||
load_order = calloc(n_libs + 1, sizeof(GtkLib *));
|
load_order = calloc(n_libs + 1, sizeof(GtkLib *));
|
||||||
|
if (load_order == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
int i, first = 0;
|
int i, first = 0;
|
||||||
for (i = 0; i < n_libs; i++) {
|
for (i = 0; i < n_libs; i++) {
|
||||||
@ -85,6 +88,7 @@ static GtkLib** get_libs_order(GtkVersion version) {
|
|||||||
|
|
||||||
static GtkLib* get_loaded() {
|
static GtkLib* get_loaded() {
|
||||||
GtkLib** libs = get_libs_order(GTK_ANY);
|
GtkLib** libs = get_libs_order(GTK_ANY);
|
||||||
|
if (libs == NULL) return NULL;
|
||||||
while(!gtk && *libs) {
|
while(!gtk && *libs) {
|
||||||
GtkLib* lib = *libs++;
|
GtkLib* lib = *libs++;
|
||||||
if (lib->check(lib->vname, /* load = */FALSE)) {
|
if (lib->check(lib->vname, /* load = */FALSE)) {
|
||||||
@ -111,7 +115,7 @@ gboolean gtk_load(JNIEnv *env, GtkVersion version, gboolean verbose) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
GtkLib** libs = get_libs_order(version);
|
GtkLib** libs = get_libs_order(version);
|
||||||
while (!gtk && *libs) {
|
while (!gtk && libs && *libs) {
|
||||||
lib = *libs++;
|
lib = *libs++;
|
||||||
if (version == GTK_ANY || lib->version == version) {
|
if (version == GTK_ANY || lib->version == version) {
|
||||||
if (verbose) {
|
if (verbose) {
|
||||||
@ -141,6 +145,7 @@ gboolean gtk_load(JNIEnv *env, GtkVersion version, gboolean verbose) {
|
|||||||
|
|
||||||
static gboolean check_version(GtkVersion version) {
|
static gboolean check_version(GtkVersion version) {
|
||||||
GtkLib** libs = get_libs_order(version);
|
GtkLib** libs = get_libs_order(version);
|
||||||
|
if (libs == NULL) return FALSE;
|
||||||
while (*libs) {
|
while (*libs) {
|
||||||
GtkLib* lib = *libs++;
|
GtkLib* lib = *libs++;
|
||||||
if (lib->check(lib->vname, /* load = */TRUE)) {
|
if (lib->check(lib->vname, /* load = */TRUE)) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user