From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: Gerd Hoffmann <kraxel@redhat.com>, Frediano Ziglio <fziglio@redhat.com>
Subject: [Qemu-devel] [PULL 2/5] audio: Do not check for audio_calloc failure
Date: Thu, 28 Feb 2019 11:08:55 +0100 [thread overview]
Message-ID: <20190228100858.28397-3-kraxel@redhat.com> (raw)
In-Reply-To: <20190228100858.28397-1-kraxel@redhat.com>
From: Frediano Ziglio <fziglio@redhat.com>
audio_calloc uses g_malloc0 which never returns in case of
memory failure.
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Message-id: 20190225154335.11397-2-fziglio@redhat.com
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
audio/audio.c | 48 ++++++------------------------------------------
1 file changed, 6 insertions(+), 42 deletions(-)
diff --git a/audio/audio.c b/audio/audio.c
index 472721a7a9f0..909c817103c8 100644
--- a/audio/audio.c
+++ b/audio/audio.c
@@ -811,12 +811,7 @@ static int audio_attach_capture (HWVoiceOut *hw)
SWVoiceOut *sw;
HWVoiceOut *hw_cap = &cap->hw;
- sc = audio_calloc(__func__, 1, sizeof(*sc));
- if (!sc) {
- dolog ("Could not allocate soft capture voice (%zu bytes)\n",
- sizeof (*sc));
- return -1;
- }
+ sc = g_malloc0(sizeof(*sc));
sc->cap = cap;
sw = &sc->sw;
@@ -1960,15 +1955,10 @@ CaptureVoiceOut *AUD_add_capture (
if (audio_validate_settings (as)) {
dolog ("Invalid settings were passed when trying to add capture\n");
audio_print_settings (as);
- goto err0;
+ return NULL;
}
- cb = audio_calloc(__func__, 1, sizeof(*cb));
- if (!cb) {
- dolog ("Could not allocate capture callback information, size %zu\n",
- sizeof (*cb));
- goto err0;
- }
+ cb = g_malloc0(sizeof(*cb));
cb->ops = *ops;
cb->opaque = cb_opaque;
@@ -1981,12 +1971,7 @@ CaptureVoiceOut *AUD_add_capture (
HWVoiceOut *hw;
CaptureVoiceOut *cap;
- cap = audio_calloc(__func__, 1, sizeof(*cap));
- if (!cap) {
- dolog ("Could not allocate capture voice, size %zu\n",
- sizeof (*cap));
- goto err1;
- }
+ cap = g_malloc0(sizeof(*cap));
hw = &cap->hw;
QLIST_INIT (&hw->sw_head);
@@ -1994,23 +1979,11 @@ CaptureVoiceOut *AUD_add_capture (
/* XXX find a more elegant way */
hw->samples = 4096 * 4;
- hw->mix_buf = audio_calloc(__func__, hw->samples,
- sizeof(struct st_sample));
- if (!hw->mix_buf) {
- dolog ("Could not allocate capture mix buffer (%d samples)\n",
- hw->samples);
- goto err2;
- }
+ hw->mix_buf = g_new0(struct st_sample, hw->samples);
audio_pcm_init_info (&hw->info, as);
- cap->buf = audio_calloc(__func__, hw->samples, 1 << hw->info.shift);
- if (!cap->buf) {
- dolog ("Could not allocate capture buffer "
- "(%d samples, each %d bytes)\n",
- hw->samples, 1 << hw->info.shift);
- goto err3;
- }
+ cap->buf = g_malloc0_n(hw->samples, 1 << hw->info.shift);
hw->clip = mixeng_clip
[hw->info.nchannels == 2]
@@ -2025,15 +1998,6 @@ CaptureVoiceOut *AUD_add_capture (
audio_attach_capture (hw);
}
return cap;
-
- err3:
- g_free (cap->hw.mix_buf);
- err2:
- g_free (cap);
- err1:
- g_free (cb);
- err0:
- return NULL;
}
}
--
2.9.3
next prev parent reply other threads:[~2019-02-28 10:09 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-28 10:08 [Qemu-devel] [PULL 0/5] Audio 20190228 patches Gerd Hoffmann
2019-02-28 10:08 ` [Qemu-devel] [PULL 1/5] audio: Use g_strdup_printf instead of manual building a string Gerd Hoffmann
2019-02-28 10:08 ` Gerd Hoffmann [this message]
2019-02-28 10:08 ` [Qemu-devel] [PULL 3/5] audio: don't build alsa and sdl by default on linux Gerd Hoffmann
2019-02-28 10:08 ` [Qemu-devel] [PULL 4/5] audio/sdlaudio: Remove the semaphore code Gerd Hoffmann
2019-02-28 10:08 ` [Qemu-devel] [PULL 5/5] audio/sdlaudio: Simplify the sdl_callback function Gerd Hoffmann
2019-02-28 17:35 ` [Qemu-devel] [PULL 0/5] Audio 20190228 patches Peter Maydell
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=20190228100858.28397-3-kraxel@redhat.com \
--to=kraxel@redhat.com \
--cc=fziglio@redhat.com \
--cc=qemu-devel@nongnu.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;
as well as URLs for NNTP newsgroup(s).