<div dir="ltr">On Sat, Sep 21, 2013 at 10:54 AM, Rafaël Carré <span dir="ltr"><<a href="mailto:funman@videolan.org" target="_blank">funman@videolan.org</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">---<br>
modules/codec/opus.c | 35 ++++++++++++++++-------------------<br>
1 file changed, 16 insertions(+), 19 deletions(-)<br>
<br>
diff --git a/modules/codec/opus.c b/modules/codec/opus.c<br>
index fa96d2c..2f50b77 100644<br>
--- a/modules/codec/opus.c<br>
+++ b/modules/codec/opus.c<br>
@@ -571,6 +571,9 @@ static int OpenEncoder(vlc_object_t *p_this)<br>
if (!sys)<br>
return VLC_ENOMEM;<br>
<br>
+ sys->buffer = NULL;<br>
+ sys->enc = NULL;<br>
+<br>
enc->pf_encode_audio = Encode;<br>
enc->fmt_in.i_codec = VLC_CODEC_FL32;<br>
enc->fmt_in.audio.i_rate = /* Only 48kHz */<br>
@@ -584,8 +587,7 @@ static int OpenEncoder(vlc_object_t *p_this)<br>
&header))<br>
{<br>
msg_Err(enc, "Failed to prepare header.");<br>
- free(sys);<br>
- return VLC_ENOMEM;<br>
+ goto error;<br>
}<br>
<br>
/* needed for max encoded size calculation */<br>
@@ -601,8 +603,8 @@ static int OpenEncoder(vlc_object_t *p_this)<br>
if (err != OPUS_OK)<br>
{<br>
msg_Err(enc, "Could not create encoder: error %d", err);<br>
- free(sys);<br>
- return VLC_EGENERIC;<br>
+ sys->enc = NULL;<br>
+ goto error;<br>
}<br>
<br>
/* TODO: vbr, bitrate, fec */<br>
@@ -612,11 +614,7 @@ static int OpenEncoder(vlc_object_t *p_this)<br>
enc->p_sys = sys;<br>
sys->buffer = malloc(OPUS_FRAME_SIZE * header.channels * sizeof(float));<br>
if (!sys->buffer)<br>
- {<br>
- opus_multistream_encoder_destroy(sys->enc);<br>
- free(sys);<br>
- return VLC_ENOMEM;<br>
- }<br>
+ goto error;<br>
<br>
sys->i_nb_samples = 0;<br>
<br>
@@ -634,10 +632,7 @@ static int OpenEncoder(vlc_object_t *p_this)<br>
&enc->fmt_out.i_extra, &header))<br>
{<br>
msg_Err(enc, "Failed to write header.");<br>
- free(sys->buffer);<br>
- opus_multistream_encoder_destroy(sys->enc);<br>
- free(sys);<br>
- return VLC_ENOMEM;<br>
+ goto error;<br>
}<br>
<br>
if (sys->i_samples_delay > 0)<br>
@@ -646,12 +641,7 @@ static int OpenEncoder(vlc_object_t *p_this)<br>
enc->fmt_out.audio.i_channels;<br>
sys->padding = block_Alloc(padding_samples * sizeof(float));<br>
if (!sys->padding)<br>
- {<br>
- free(sys->buffer);<br>
- opus_multistream_encoder_destroy(sys->enc);<br>
- free(sys);<br>
- return VLC_ENOMEM;<br>
- }<br>
+ goto error;<br>
sys->padding->i_nb_samples = sys->i_samples_delay;<br>
float *pad_ptr = (float *) sys->padding->p_buffer;<br>
memset(pad_ptr, 0, padding_samples * sizeof(float));<br>
@@ -662,6 +652,13 @@ static int OpenEncoder(vlc_object_t *p_this)<br>
}<br>
<br>
return VLC_SUCCESS;<br>
+<br>
+error:<br>
+ if (sys->enc)<br>
+ opus_multistream_encoder_destroy(sys->enc);<br>
+ free(sys->buffer);<br>
+ free(sys);<br>
+ return VLC_EGENERIC;<br>
}<br clear="all"></blockquote><div><br></div><div>The only issue I see here is that we're no longer distinguishing between out of memory errors and generic error cases. Maybe that distinction isn't so important in this situation.<br>
</div></div><br></div><div class="gmail_extra">In any case, the patchset looks good, should i resend with your changes merged?<br><br></div><div class="gmail_extra">Best,<br>Tristan<br><br></div><div class="gmail_extra">-- <br>
Tristan Matthews<br>web: <a href="http://tristanswork.blogspot.com">http://tristanswork.blogspot.com</a><br>
</div></div>