Program: 107634
Project: 107634
Buggy source:
/** 
 * Initializes a new <tt>IAudioClient</tt> instance for an audio endpoint device identified by a specific <tt>MediaLocator</tt>. The initialization is performed to an extent suitable for the operation of  {@link WASAPIRenderer} and {@link WASAPIStream}.
 * @param locator a <tt>MediaLocator</tt> which identifies the audioendpoint device to initialize a new <tt>IAudioClient</tt> instance for
 * @param dataFlow the flow of media data to be supported by the audioendpoint device identified by the specified <tt>locator</tt>
 * @param streamFlags
 * @param eventHandle
 * @param hnsBufferDuration the base of the duration in milliseconds of thebuffer that the audio application will share with the audio engine. If {@link Format#NOT_SPECIFIED}, the method uses the default interval between periodic passes by the audio engine.
 * @param formats an array of alternative <tt>AudioFormat</tt>s with whichinitialization of a new <tt>IAudioClient</tt> instance is to be attempted. The first element of the <tt>formats</tt> array which is supported by the new <tt>IAudioClient</tt> instance is used to initialize it and any preceding elements are set to <tt>null</tt> to signify that they are not supported and to make it possible to retrieve the <tt>AudioFormat</tt> with which the new <tt>IAudioClient</tt> instance has been initialized.
 * @return a new <tt>IAudioClient</tt> instance initialized for the audioendpoint device identified by the specified <tt>locator</tt>
 * @throws HResultException if an error occurs while initializing a new<tt>IAudioClient</tt> for the audio endpoint device identified by the specified <tt>locator</tt> in a native WASAPI function which returns an <tt>HRESULT</tt> value
 */
public long initializeIAudioClient(MediaLocator locator,DataFlow dataFlow,int streamFlags,long eventHandle,long hnsBufferDuration,AudioFormat[] formats) throws HResultException {
  WASAPISystem.CoInitializeEx();
  String id=locator.getRemainder();
  long iMMDevice=getIMMDevice(id);
  if (iMMDevice == 0) {
    throw new RuntimeException("String_Node_Str" + "String_Node_Str" + id);
  }
  long ret=0;
  try {
    int iMMDeviceDataFlow=getIMMDeviceDataFlow(iMMDevice);
switch (dataFlow) {
case CAPTURE:
      if ((iMMDeviceDataFlow != eAll) && (iMMDeviceDataFlow != eCapture))       throw new IllegalArgumentException("String_Node_Str");
    break;
case NOTIFY:
case PLAYBACK:
  if ((iMMDeviceDataFlow != eAll) && (iMMDeviceDataFlow != eRender))   throw new IllegalArgumentException("String_Node_Str");
break;
}
long iAudioClient=IMMDevice_Activate(iMMDevice,IID_IAudioClient,CLSCTX_ALL,0);
if (iAudioClient == 0) throw new RuntimeException("String_Node_Str");
try {
long waveformatex=WAVEFORMATEX_alloc();
if (waveformatex == 0) throw new OutOfMemoryError("String_Node_Str");
try {
int shareMode=AUDCLNT_SHAREMODE_SHARED;
boolean waveformatexIsInitialized=false;
for (int i=0; i < formats.length; i++) {
  WAVEFORMATEX_fill(waveformatex,formats[i]);
  long pClosestMatch=IAudioClient_IsFormatSupported(iAudioClient,shareMode,waveformatex);
  if (pClosestMatch == 0)   formats[i]=null;
 else {
    try {
      if (pClosestMatch == waveformatex) {
        waveformatexIsInitialized=true;
        break;
      }
 else {
        formats[i]=null;
      }
    }
  finally {
      if (pClosestMatch != waveformatex)       CoTaskMemFree(pClosestMatch);
    }
  }
}
if (!waveformatexIsInitialized) throw new IllegalArgumentException("String_Node_Str");
streamFlags|=AUDCLNT_STREAMFLAGS_NOPERSIST;
if (eventHandle != 0) streamFlags|=AUDCLNT_STREAMFLAGS_EVENTCALLBACK;
if (hnsBufferDuration == Format.NOT_SPECIFIED) {
  hnsBufferDuration=IAudioClient_GetDefaultDevicePeriod(iAudioClient) / 10000;
  if (hnsBufferDuration <= 1) {
    hnsBufferDuration=WASAPISystem.DEFAULT_DEVICE_PERIOD;
  }
}
int hresult=IAudioClient_Initialize(iAudioClient,shareMode,streamFlags,3 * hnsBufferDuration * 10000,0,waveformatex,audioSessionGuid);
if (hresult != S_OK) {
  throw new HResultException(hresult);
}
if (((streamFlags & AUDCLNT_STREAMFLAGS_EVENTCALLBACK) == AUDCLNT_STREAMFLAGS_EVENTCALLBACK) && (eventHandle != 0)) {
  IAudioClient_SetEventHandle(iAudioClient,eventHandle);
}
ret=iAudioClient;
iAudioClient=0;
}
  finally {
CoTaskMemFree(waveformatex);
}
}
  finally {
if (iAudioClient != 0) IAudioClient_Release(iAudioClient);
}
}
  finally {
if (iMMDevice != 0) IMMDevice_Release(iMMDevice);
}
return ret;
}

Fixed version (ground truth):
/** 
 * Initializes a new <tt>IAudioClient</tt> instance for an audio endpoint device identified by a specific <tt>MediaLocator</tt>. The initialization is performed to an extent suitable for the operation of  {@link WASAPIRenderer} and {@link WASAPIStream}.
 * @param locator a <tt>MediaLocator</tt> which identifies the audioendpoint device to initialize a new <tt>IAudioClient</tt> instance for
 * @param dataFlow the flow of media data to be supported by the audioendpoint device identified by the specified <tt>locator</tt>
 * @param streamFlags
 * @param eventHandle
 * @param hnsBufferDuration the base of the duration in milliseconds of thebuffer that the audio application will share with the audio engine. If {@link Format#NOT_SPECIFIED}, the method uses the default interval between periodic passes by the audio engine.
 * @param formats an array of alternative <tt>AudioFormat</tt>s with whichinitialization of a new <tt>IAudioClient</tt> instance is to be attempted. The first element of the <tt>formats</tt> array which is supported by the new <tt>IAudioClient</tt> instance is used to initialize it and any preceding elements are set to <tt>null</tt> to signify that they are not supported and to make it possible to retrieve the <tt>AudioFormat</tt> with which the new <tt>IAudioClient</tt> instance has been initialized.
 * @return a new <tt>IAudioClient</tt> instance initialized for the audioendpoint device identified by the specified <tt>locator</tt>
 * @throws HResultException if an error occurs while initializing a new<tt>IAudioClient</tt> for the audio endpoint device identified by the specified <tt>locator</tt> in a native WASAPI function which returns an <tt>HRESULT</tt> value
 */
public long initializeIAudioClient(MediaLocator locator,DataFlow dataFlow,int streamFlags,long eventHandle,long hnsBufferDuration,AudioFormat[] formats) throws HResultException {
  WASAPISystem.CoInitializeEx();
  String id=locator.getRemainder();
  long iMMDevice=getIMMDevice(id);
  if (iMMDevice == 0) {
    throw new RuntimeException("String_Node_Str" + "String_Node_Str" + id);
  }
  long ret=0;
  try {
    int iMMDeviceDataFlow=getIMMDeviceDataFlow(iMMDevice);
switch (dataFlow) {
case CAPTURE:
      if ((iMMDeviceDataFlow != eAll) && (iMMDeviceDataFlow != eCapture))       throw new IllegalArgumentException("String_Node_Str");
    break;
case NOTIFY:
case PLAYBACK:
  if ((iMMDeviceDataFlow != eAll) && (iMMDeviceDataFlow != eRender))   throw new IllegalArgumentException("String_Node_Str");
break;
}
long iAudioClient=IMMDevice_Activate(iMMDevice,IID_IAudioClient,CLSCTX_ALL,0);
if (iAudioClient == 0) throw new RuntimeException("String_Node_Str");
try {
long waveformatex=WAVEFORMATEX_alloc();
if (waveformatex == 0) throw new OutOfMemoryError("String_Node_Str");
try {
int shareMode=AUDCLNT_SHAREMODE_SHARED;
int waveformatexIsInitialized=Format.NOT_SPECIFIED;
for (int i=0; i < formats.length; i++) {
  WAVEFORMATEX_fill(waveformatex,formats[i]);
  long pClosestMatch=IAudioClient_IsFormatSupported(iAudioClient,shareMode,waveformatex);
  if (pClosestMatch == 0) {
  }
 else {
    try {
      if (pClosestMatch == waveformatex) {
        waveformatexIsInitialized=i;
        break;
      }
 else {
      }
    }
  finally {
      if (pClosestMatch != waveformatex)       CoTaskMemFree(pClosestMatch);
    }
  }
}
if ((waveformatexIsInitialized < 0) || (waveformatexIsInitialized >= formats.length)) {
  logUnsupportedFormats(dataFlow,locator,formats);
  throw new IllegalArgumentException("String_Node_Str");
}
Arrays.fill(formats,0,waveformatexIsInitialized,null);
streamFlags|=AUDCLNT_STREAMFLAGS_NOPERSIST;
if (eventHandle != 0) streamFlags|=AUDCLNT_STREAMFLAGS_EVENTCALLBACK;
if (hnsBufferDuration == Format.NOT_SPECIFIED) {
  hnsBufferDuration=IAudioClient_GetDefaultDevicePeriod(iAudioClient) / 10000;
  if (hnsBufferDuration <= 1) {
    hnsBufferDuration=WASAPISystem.DEFAULT_DEVICE_PERIOD;
  }
}
int hresult=IAudioClient_Initialize(iAudioClient,shareMode,streamFlags,3 * hnsBufferDuration * 10000,0,waveformatex,audioSessionGuid);
if (hresult != S_OK) {
  throw new HResultException(hresult);
}
if (((streamFlags & AUDCLNT_STREAMFLAGS_EVENTCALLBACK) == AUDCLNT_STREAMFLAGS_EVENTCALLBACK) && (eventHandle != 0)) {
  IAudioClient_SetEventHandle(iAudioClient,eventHandle);
}
ret=iAudioClient;
iAudioClient=0;
}
  finally {
CoTaskMemFree(waveformatex);
}
}
  finally {
if (iAudioClient != 0) IAudioClient_Release(iAudioClient);
}
}
  finally {
if (iMMDevice != 0) IMMDevice_Release(iMMDevice);
}
return ret;
}