Alsa-Devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Lennart Poettering <mznyfn@0pointer.de>
To: ALSA Development Mailing List <alsa-devel@alsa-project.org>
Subject: [PATCH 5/6] pulse: rework object destruction paths a bit
Date: Tue, 4 Aug 2009 23:55:28 +0200	[thread overview]
Message-ID: <20090804215528.GA4904@omega> (raw)

Make sure we deal better with partially initialized structs.

Don't check for pointer state before calling free() since free() does
that anyway.
---
 pulse/ctl_pulse.c |    7 ++-----
 pulse/pcm_pulse.c |   19 ++++++++++---------
 2 files changed, 12 insertions(+), 14 deletions(-)

diff --git a/pulse/ctl_pulse.c b/pulse/ctl_pulse.c
index 879f260..85863ed 100644
--- a/pulse/ctl_pulse.c
+++ b/pulse/ctl_pulse.c
@@ -606,11 +606,8 @@ static void pulse_close(snd_ctl_ext_t * ext)
 	if (ctl->p)
 		pulse_free(ctl->p);
 
-	if (ctl->source)
-		free(ctl->source);
-	if (ctl->sink)
-		free(ctl->sink);
-
+	free(ctl->source);
+	free(ctl->sink);
 	free(ctl);
 }
 
diff --git a/pulse/pcm_pulse.c b/pulse/pcm_pulse.c
index 98983f8..02a837e 100644
--- a/pulse/pcm_pulse.c
+++ b/pulse/pcm_pulse.c
@@ -819,21 +819,22 @@ static int pulse_close(snd_pcm_ioplug_t * io)
 
 	assert(pcm);
 
-	pa_threaded_mainloop_lock(pcm->p->mainloop);
+	if (pcm->p && pcm->p->mainloop) {
 
-	if (pcm->stream) {
-		pa_stream_disconnect(pcm->stream);
-		pa_stream_unref(pcm->stream);
-	}
+		pa_threaded_mainloop_lock(pcm->p->mainloop);
 
-	pa_threaded_mainloop_unlock(pcm->p->mainloop);
+		if (pcm->stream) {
+			pa_stream_disconnect(pcm->stream);
+			pa_stream_unref(pcm->stream);
+		}
+
+		pa_threaded_mainloop_unlock(pcm->p->mainloop);
+	}
 
 	if (pcm->p)
 		pulse_free(pcm->p);
 
-	if (pcm->device)
-		free(pcm->device);
-
+	free(pcm->device);
 	free(pcm);
 
 	return 0;
-- 
1.6.4



Lennart

-- 
Lennart Poettering                        Red Hat, Inc.
lennart [at] poettering [dot] net         ICQ# 11060553
http://0pointer.net/lennart/           GnuPG 0x1A015CC4

                 reply	other threads:[~2009-08-04 21:55 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090804215528.GA4904@omega \
    --to=mznyfn@0pointer.de \
    --cc=alsa-devel@alsa-project.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox