Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pulseaudio: fix PaPulseAudio_Initialize unlocking #852

Merged

Conversation

illuusio
Copy link
Collaborator

@illuusio illuusio commented Oct 14, 2023

When PaPulseAudio_Initialize fails it does not currently do it very well as bug report #848 tells. Now Only free lock if it's initialized enough to be unlocked.

Unlocking is done after allocations are done. That is because Locking is just after allocations and next goto error should have allocated memory and drop to that. Also now Group freeing code is one place.

Resolves #848

@illuusio illuusio force-pushed the pulseaudio-papulseaudio_initialize-848 branch 2 times, most recently from a53789e to ba8f5f0 Compare October 14, 2023 14:44
src/hostapi/pulseaudio/pa_linux_pulseaudio.c Outdated Show resolved Hide resolved
src/hostapi/pulseaudio/pa_linux_pulseaudio.c Outdated Show resolved Hide resolved
Copy link
Collaborator

@RossBencina RossBencina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a suggestion...

src/hostapi/pulseaudio/pa_linux_pulseaudio.c Show resolved Hide resolved
@illuusio illuusio force-pushed the pulseaudio-papulseaudio_initialize-848 branch 3 times, most recently from f6fbdfb to 96fa25d Compare October 24, 2023 13:37
@illuusio illuusio self-assigned this Oct 30, 2023
@illuusio illuusio requested a review from philburk October 30, 2023 14:33
@kleinerm
Copy link
Contributor

kleinerm commented Nov 2, 2023

@illuusio Changes look good to me. I also gave it a quick test and it worked.

@@ -589,6 +597,7 @@ PaError PaPulseAudio_Initialize( PaUtilHostApiRepresentation ** hostApi,
break;
case PA_CONTEXT_TERMINATED:
case PA_CONTEXT_FAILED:
result = paUnanticipatedHostError;
Copy link
Collaborator

@RossBencina RossBencina Nov 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there's a missing call to PaUtil_SetLastHostErrorInfo or PA_PULSEAUDIO_SET_LAST_HOST_ERROR here. perhaps separate calls for each case.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll work this out in other PR as I noticed that error reporting is not up-to-date. I this is mandatory I'll add it in here but it would be easier to have own PR to make sure every Error report is correct not just this one.

Copy link
Collaborator

@RossBencina RossBencina Nov 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fine (and good) to do additional cleanup later, but this PR adds a paUnanticipatedHostError. Our policy is to not accept PRs that introduce new problems, so we'd appreciate it if you could fix this case in this PR please.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok now it should be solved

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, but now the first parameter to PA_PULSEAUDIO_SET_LAST_HOST_ERROR is not correct. It should be the native error code definitely not a PortAudio error code. For this PR, you could just set it to 0 if you don't have anything better. For further info check the definition of PA_PULSEAUDIO_SET_LAST_HOST_ERROR in pa_linux_pulseaudio_internal.h and then the definition of PaUtil_SetLastHostErrorInfo in pa_util.h.

Also, initiliaze is mis-spelled on line 606.

While I'm here, note that you'll need to fix the PA_PULSEAUDIO_SET_LAST_HOST_ERROR in a later PR to pass the correct host api type.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've correct the errors and spelling and actually hostapi type is fixed in another PR but I can fix it here if it's needed.

Copy link
Collaborator Author

@illuusio illuusio Dec 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've removed those new error codes and now it behaves as it was before only it goes to error (problem is that it just return PaNoError) but as it did worked like that lately it should be ok.

@illuusio illuusio force-pushed the pulseaudio-papulseaudio_initialize-848 branch from 96fa25d to 233152a Compare November 17, 2023 14:00
@illuusio illuusio force-pushed the pulseaudio-papulseaudio_initialize-848 branch 2 times, most recently from 33d8b89 to 029df8a Compare November 24, 2023 15:56
Make sure that if PaPulseAudio_Initialize fails that
a) Mainloop is unlocked if HostAPI is initialized
b) Unlocking is done before freeing
c) It's done only once

Also move allocations group freeing code to correct place
now there only one place where it's called
@illuusio illuusio force-pushed the pulseaudio-papulseaudio_initialize-848 branch from 029df8a to 8efc877 Compare December 6, 2023 10:02
@philburk philburk merged commit 34078a7 into PortAudio:master Dec 22, 2023
9 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PaPulseAudio_Initialize does not unlock correctly on error path
4 participants