@@ -680,6 +680,7 @@ NTSTATUS SarCreateEndpoint(
680680 request->name [MAX_ENDPOINT_NAME_LENGTH] = ' \0 ' ;
681681 request->id [MAX_ENDPOINT_NAME_LENGTH] = ' \0 ' ;
682682 RtlInitUnicodeString (&endpoint->deviceName , request->name );
683+ RtlInitUnicodeString (&endpoint->deviceId , request->id );
683684 status = SarStringDuplicate (
684685 &endpoint->deviceName , &endpoint->deviceName );
685686
@@ -688,6 +689,12 @@ NTSTATUS SarCreateEndpoint(
688689 }
689690
690691 deviceNameAllocated = TRUE ;
692+ status = SarStringDuplicate (
693+ &endpoint->deviceId , &endpoint->deviceId );
694+
695+ if (!NT_SUCCESS (status)) {
696+ goto err_out;
697+ }
691698
692699 // Windows 10 introduces a 'format cache' which at this time appears to
693700 // not fully invalidate itself when KSEVENT_PINCAPS_FORMATCHANGE is
@@ -705,24 +712,24 @@ NTSTATUS SarCreateEndpoint(
705712 RtlUnicodeStringPrintf (&deviceIdBuffer,
706713 L" %ws_%d_%d_%d" , request->id , request->channelCount ,
707714 controlContext->sampleRate , controlContext->sampleSize );
708- status = SarStringDuplicate (&endpoint->deviceId , &deviceIdBuffer);
715+ status = SarStringDuplicate (
716+ &endpoint->deviceIdMangled , &deviceIdBuffer);
709717
710718 if (!NT_SUCCESS (status)) {
711719 goto err_out;
712720 }
713721 } else {
714- RtlInitUnicodeString (&endpoint-> deviceId , request-> id );
715- status = SarStringDuplicate ( &endpoint->deviceId , &endpoint->deviceId );
722+ status = SarStringDuplicate (
723+ &endpoint->deviceIdMangled , &endpoint->deviceId );
716724
717725 if (!NT_SUCCESS (status)) {
718726 goto err_out;
719727 }
720728 }
721729
722- deviceIdAllocated = TRUE ;
723730 KsAcquireDevice (ksDevice);
724731 status = KsCreateFilterFactory (
725- device, endpoint->filterDesc , endpoint->deviceId .Buffer ,
732+ device, endpoint->filterDesc , endpoint->deviceIdMangled .Buffer ,
726733 nullptr , KSCREATE_ITEM_FREEONSTOP,
727734 nullptr , nullptr , &endpoint->filterFactory );
728735 KsReleaseDevice (ksDevice);
@@ -799,6 +806,10 @@ VOID SarDeleteEndpoint(SarEndpoint *endpoint)
799806 SarStringFree (&endpoint->deviceId );
800807 }
801808
809+ if (endpoint->deviceIdMangled .Buffer ) {
810+ SarStringFree (&endpoint->deviceIdMangled );
811+ }
812+
802813 ExFreePoolWithTag (endpoint, SAR_TAG);
803814}
804815
0 commit comments