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

Delete sound in CActiveAE::DiscardSound #4883

Merged
merged 1 commit into from
Jun 14, 2014
Merged

Delete sound in CActiveAE::DiscardSound #4883

merged 1 commit into from
Jun 14, 2014

Conversation

ruuk
Copy link
Member

@ruuk ruuk commented Jun 10, 2014

In pull request #4491, I added the useCached arg to xbmc.playSFX() which when set to false would cause the cached sound to be freed and the same filename loaded again. One assumption that I made was that CAEFactory::FreeSound() actually freed the sound. On further testing this has turned out not to be the case, and using playSFX() in this manner exposes a memory leak. I looked closer and found that FreeSound() ultimately causes a call to CActiveAE::DiscardSound() and while the sound is removed from a map of sounds I couldn't find anywhere where the sound was deleted. This adds that.

While this seems to me like it should be there regardless and greatly reduces the memory leak (by about a factor of 8) there still seems to be a leak. I can't seem to figure out why.

Below is a link to a small testing addon which demonstrates the leak.

http://2ndmind.com/xbmc/test/script.ruuk.testing-0.0.8.zip

@jmarshallnz
Copy link
Contributor

Seems it doesn't get deleted anywhere else.

@FernetMenta @fritsch mind taking a look?

@FernetMenta
Copy link
Contributor

Yes, this looks good. Thanks!

@jmarshallnz
Copy link
Contributor

jenkins build this please

@fritsch
Copy link
Member

fritsch commented Jun 11, 2014

For now it's only used from the statemachine and read from a message, but perhaps setting it to null after delete also would take care of future errors?

@FernetMenta
Copy link
Contributor

too early for you? :)
sound is an argument of DiscardSound(), m_sounds is a vector. what exactly you want to set NULL?

@fritsch
Copy link
Member

fritsch commented Jun 11, 2014

Not too early, it is good practice that one nulls a local ptr whenever one removes the corresponding element (where it points to) from a datastructure (m_sounds). Whoever calls DiscardSound or better said erase should care for that.

Edit: http://stackoverflow.com/questions/704466/why-doesnt-delete-set-the-pointer-to-null <- seems the maker of c++ is the same oppinion on this early morning.

@FernetMenta
Copy link
Contributor

there is a return statement directly following the delete. I don't get your point, please post a diff

@whaupt
Copy link
Contributor

whaupt commented Jun 11, 2014

I guess this code needs to be fast - is this why you use plain pointers in those std::vectors?

@FernetMenta
Copy link
Contributor

I guess this code needs to be fast - is this why you use plain pointers in those std::vectors?

what would you suggest?

@fritsch
Copy link
Member

fritsch commented Jun 11, 2014

I already said, that it does not matter in current code! But as Discard also does a delete everyone that calls DiscardSound will end with a dangling ptr.

Consider the following:

          sound = *(CActiveAESound**)msg->data;
          DiscardSound(sound);
          CLog::Log("Sound has volume: %d", sound->GetVolume());
          sound->SetVolume(0.5f);

Yeah I know, you don't want to consider things that not happen, but interface functions should be aware of dumb callers. The above scenario would corrupt the heap and most likely found after a whole lot of debugging, btw. DiscardSound is not documented to do a real delete of data. Consider reusing of that buffer and so on.

Edit: The other functions have at least a "Free" in the name.

@fritsch
Copy link
Member

fritsch commented Jun 11, 2014

And: as the original message was FREESOUND the corresponding FreeSound function should be used.

@whaupt
Copy link
Contributor

whaupt commented Jun 11, 2014

what would you suggest?

I was just curious if there is a reason not to use smart pointers in those std::vectors.
But I guess fritsch just gave the answer when considering buffer reuse etc.

@FernetMenta
Copy link
Contributor

but interface functions should be aware of dumb callers.

DiscardSound is NOT an interface function. It is a protected helper method only used by the state machine.

I was just curious if there is a reason not to use smart pointers in those std::vectors

C++ 10 has no smart pointers and I consider boost a no go.

@whaupt
Copy link
Contributor

whaupt commented Jun 11, 2014

C++ 10 has no smart pointers and I consider boost a no go.

Reason enough :)

@FernetMenta
Copy link
Contributor

my last comment here @fritsch

And: as the original message was FREESOUND the corresponding FreeSound function should be used.

You may have noticed that FreeSound IS the public interface function. I needed to find a new name for it. Some others of those a prefixed with an S for state machine. Feel free to fix this inconsistency.

@fritsch
Copy link
Member

fritsch commented Jun 11, 2014

That's fine. Will send a PR after that one is in.

@MartijnKaijser MartijnKaijser added this to the Pending for inclusion milestone Jun 11, 2014
@ruuk
Copy link
Member Author

ruuk commented Jun 14, 2014

Should I set it to null after the delete, or did we decide to leave it as is?

@FernetMenta
Copy link
Contributor

it's fine as is. it has a Gotham label so we wait for RMs to push the buton.

@ruuk
Copy link
Member Author

ruuk commented Jun 14, 2014

Ok, thanks.

@MartijnKaijser MartijnKaijser modified the milestones: Helix 14.0-alpha1, Pending for inclusion Jun 14, 2014
jmarshallnz added a commit that referenced this pull request Jun 14, 2014
Delete sound in CActiveAE::DiscardSound
@jmarshallnz jmarshallnz merged commit a9655c3 into xbmc:master Jun 14, 2014
@jmarshallnz
Copy link
Contributor

At your service :)

jmarshallnz added a commit to jmarshallnz/xbmc that referenced this pull request Jun 15, 2014
Delete sound in CActiveAE::DiscardSound
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.

None yet

6 participants