From b7d6fff50fbee0a56739f622f9e0d1711678766f Mon Sep 17 00:00:00 2001 From: "dgreid@chromium.org" Date: Tue, 12 Jun 2012 09:17:07 +0000 Subject: CrasOutput: Handle Close() being called after a failed Open(). If Open() fails due to the pipe() or pthread_create() system calls failing, client_ will be non-null but will have been freed. To fix this, set client_ to NULL on failures in Open(), and check before using it in Close(). BUG=132040 TEST=Change the cras library to return errors from the client_connect() or client_run() functions, then watch as the errors cause a crash when you add an audio stream. Review URL: https://chromiumcodereview.appspot.com/10546090 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@141638 0039d316-1c4b-4281-b951-d872f2087c98 --- media/audio/linux/cras_output.cc | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'media/audio/linux/cras_output.cc') diff --git a/media/audio/linux/cras_output.cc b/media/audio/linux/cras_output.cc index a04388a..77eb68f 100644 --- a/media/audio/linux/cras_output.cc +++ b/media/audio/linux/cras_output.cc @@ -120,6 +120,7 @@ bool CrasOutputStream::Open() { int err = cras_client_create(&client_); if (err < 0) { LOG(WARNING) << "Couldn't create CRAS client.\n"; + client_ = NULL; TransitionTo(kInError); return false; } @@ -127,6 +128,7 @@ bool CrasOutputStream::Open() { if (err) { LOG(WARNING) << "Couldn't connect CRAS client.\n"; cras_client_destroy(client_); + client_ = NULL; TransitionTo(kInError); return false; } @@ -135,6 +137,7 @@ bool CrasOutputStream::Open() { if (err) { LOG(WARNING) << "Couldn't run CRAS client.\n"; cras_client_destroy(client_); + client_ = NULL; TransitionTo(kInError); return false; } @@ -149,8 +152,11 @@ void CrasOutputStream::Close() { return; } - cras_client_stop(client_); - cras_client_destroy(client_); + if (client_) { + cras_client_stop(client_); + cras_client_destroy(client_); + client_ = NULL; + } // Signal to the manager that we're closed and can be removed. // Should be last call in the method as it deletes "this". -- cgit v1.1