< prev index next >

src/java.desktop/macosx/native/libjsound/PLATFORM_API_MacOSX_Ports.cpp

Print this page
rev 56159 : 8230480: check malloc/calloc results in java.desktop

@@ -412,15 +412,22 @@
 // returns java control
 static void* CreatePortControl(PortMixer *mixer, PortControlCreator *creator, PortControl::ControlType type,
                                AudioControl **audioControls, int offset, int len) {
     void *jControl = NULL;
     PortControl *control = (PortControl *)calloc(1, sizeof(PortControl));
+    if (control == NULL) {
+        return NULL;
+    }
     float precision = 0.01;
 
     control->type = type;
     control->controlCount = len;
     control->audioControls = (AudioControl **)malloc(len * sizeof(AudioControl *));
+    if (control->audioControls == NULL) {
+        free(control);
+        return NULL;
+    }
     memcpy(control->audioControls, audioControls + offset, len * sizeof(AudioControl *));
 
     switch (control->type) {
     case PortControl::Volume:
         jControl = creator->newFloatControl(creator, control, CONTROL_TYPE_VOLUME, 0, 1, precision, "");

@@ -480,10 +487,13 @@
 
             if (err) {
                 OS_ERROR1(err, "PORT_GetControls (portIndex = %d) get OwnedObject values", portIndex);
             } else {
                 mixer->deviceControls = (AudioControl *)calloc(mixer->deviceControlCount, sizeof(AudioControl));
+                if (mixer->deviceControls == NULL) {
+                    return;
+                }
 
                 for (int i = 0; i < mixer->deviceControlCount; i++) {
                     AudioControl *control = &mixer->deviceControls[i];
 
                     control->controlID = controlIDs[i];

@@ -613,14 +623,20 @@
                 UInt32 size = sizeof(cfname);
                 OSStatus err = AudioObjectGetPropertyData(mixer->deviceID, &address, 0, NULL, &size, &cfname);
                 if (err == noErr) {
                     CFIndex length = CFStringGetLength(cfname) + 1;
                     channelName = (char *)malloc(length);
+                    if (channelName == NULL) {
+                        return;
+                    }
                     CFStringGetCString(cfname, channelName, length, kCFStringEncodingUTF8);
                     CFRelease(cfname);
                 } else {
                     channelName = (char *)malloc(16);
+                    if (channelName == NULL) {
+                        return;
+                    }
                     sprintf(channelName, "Ch %d", ch);
                 }
 
                 void* jControls[2];
                 int controlCount = 0;
< prev index next >