From fb11459d7f68402b3293ca49c1c81290d974c4da Mon Sep 17 00:00:00 2001
From: Lyubomir Marinov <lyubomir.marinov@jitsi.org>
Date: Tue, 28 May 2013 23:04:36 +0300
Subject: [PATCH] Fixes an access violation during the initialization of the
 PortAudio integration. Reported by Tudor Berechet.

---
 .../jitsi/impl/neomedia/CoreAudioDevice.java  |  7 ++++--
 .../impl/neomedia/device/PortAudioSystem.java | 22 ++++++++++++++-----
 2 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/src/org/jitsi/impl/neomedia/CoreAudioDevice.java b/src/org/jitsi/impl/neomedia/CoreAudioDevice.java
index 10345ae6..07230e01 100644
--- a/src/org/jitsi/impl/neomedia/CoreAudioDevice.java
+++ b/src/org/jitsi/impl/neomedia/CoreAudioDevice.java
@@ -64,9 +64,12 @@ else if (OSUtils.IS_WINDOWS_VISTA
 
     public static native void freeDevices();
 
-    public static String getDeviceModelIdentifier(
-            String deviceUID)
+    public static String getDeviceModelIdentifier(String deviceUID)
     {
+        // Prevent an access violation in getDeviceModelIdentifierBytes.
+        if (deviceUID == null)
+            throw new NullPointerException("deviceUID");
+
         byte[] deviceModelIdentifierBytes
             = getDeviceModelIdentifierBytes(deviceUID);
         String deviceModelIdentifier
diff --git a/src/org/jitsi/impl/neomedia/device/PortAudioSystem.java b/src/org/jitsi/impl/neomedia/device/PortAudioSystem.java
index 50a6608b..9b99e2e6 100644
--- a/src/org/jitsi/impl/neomedia/device/PortAudioSystem.java
+++ b/src/org/jitsi/impl/neomedia/device/PortAudioSystem.java
@@ -548,12 +548,22 @@ protected void doInitialize()
                 = Pa.DeviceInfo_getTransportType(deviceInfo);
             String deviceUID
                 = Pa.DeviceInfo_getDeviceUID(deviceInfo);
-            String modelIdentifier = null;
-            if(CoreAudioDevice.isLoaded)
+            String modelIdentifier;
+            String locatorRemainder;
+
+            if (deviceUID == null)
+            {
+                modelIdentifier = null;
+                locatorRemainder = name;
+            }
+            else
+            {
                 modelIdentifier
-                    = CoreAudioDevice.getDeviceModelIdentifier(deviceUID);
-            String deviceLocatorID
-                = (deviceUID != null)? deviceUID: name;
+                    = CoreAudioDevice.isLoaded
+                        ? CoreAudioDevice.getDeviceModelIdentifier(deviceUID)
+                        : null;
+                locatorRemainder = deviceUID;
+            }
 
             /*
              * TODO The intention of reinitialize() was to perform the
@@ -589,7 +599,7 @@ protected void doInitialize()
                     = new CaptureDeviceInfo2(
                             name,
                             new MediaLocator(
-                                    LOCATOR_PROTOCOL + ":#" + deviceLocatorID),
+                                    LOCATOR_PROTOCOL + ":#" + locatorRemainder),
                             new Format[]
                             {
                                 new AudioFormat(
-- 
GitLab