diff --git a/modules/codec/daala.c b/modules/codec/daala.c
index 5e330eecb43d39d56f78da34e6ae2e5289108ac3..faa13a2e369c399e0db17fc82d9be602c85555b9 100644
--- a/modules/codec/daala.c
+++ b/modules/codec/daala.c
@@ -768,6 +768,9 @@ static block_t *Encode( encoder_t *p_enc, picture_t *p_pict )
 
     /* Daala packet to block */
     p_block = block_Alloc( dpacket.bytes );
+    if( unlikely(p_block == NULL) )
+        return NULL;
+
     memcpy( p_block->p_buffer, dpacket.packet, dpacket.bytes );
     p_block->i_dts = p_block->i_pts = p_pict->date;
 
diff --git a/modules/codec/dvbsub.c b/modules/codec/dvbsub.c
index 6b045dd4171b5765117f3401fc551ce1d41a1d1c..6b46092a5088384fcb3141f9c6859103e7e88203 100644
--- a/modules/codec/dvbsub.c
+++ b/modules/codec/dvbsub.c
@@ -1992,6 +1992,9 @@ static block_t *Encode( encoder_t *p_enc, subpicture_t *p_subpic )
     msg_Dbg( p_enc, "encoding subpicture" );
 #endif
     p_block = block_Alloc( 64000 );
+    if( unlikely(p_block == NULL) )
+        return NULL;
+
     bs_init( s, p_block->p_buffer, p_block->i_buffer );
 
     bs_write( s, 8, 0x20 ); /* Data identifier */
@@ -2020,6 +2023,12 @@ static block_t *Encode( encoder_t *p_enc, subpicture_t *p_subpic )
 
         /* Send another (empty) subtitle to signal the end of display */
         p_block_stop = block_Alloc( 64000 );
+        if( unlikely(p_block_stop == NULL) )
+        {
+            block_Release(p_block);
+            return NULL;
+        }
+
         bs_init( s, p_block_stop->p_buffer, p_block_stop->i_buffer );
         bs_write( s, 8, 0x20 ); /* Data identifier */
         bs_write( s, 8, 0x0 );  /* Subtitle stream id */
diff --git a/modules/codec/fdkaac.c b/modules/codec/fdkaac.c
index b0c877ad649f5ed01190bb2df7b19c93f9c5ef58..bc7a85f50344c939e53305472e35c522faea30d2 100644
--- a/modules/codec/fdkaac.c
+++ b/modules/codec/fdkaac.c
@@ -388,6 +388,9 @@ static block_t *EncodeAudio(encoder_t *p_enc, block_t *p_aout_buf)
         in_buf.bufElSizes = &in_elem_size;
         block_t *p_block;
         p_block = block_Alloc(p_sys->i_maxoutputsize);
+        if (unlikely(p_block == NULL)) {
+            break;
+        }
         p_block->i_buffer = p_sys->i_maxoutputsize;
         out_ptr = p_block->p_buffer;
         out_size = p_block->i_buffer;
diff --git a/modules/codec/flac.c b/modules/codec/flac.c
index 90ffc58db66187fdd4f969129f19f4da5cb4e10d..01995293b4503888082c49fe9b96fcd7f642cec9 100644
--- a/modules/codec/flac.c
+++ b/modules/codec/flac.c
@@ -764,6 +764,11 @@ EncoderWriteCallback( const FLAC__StreamEncoder *encoder,
     }
 
     p_block = block_Alloc( bytes );
+    /* FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR would be more appropriate
+       but it's not the right type of enum */
+    if( unlikely(p_block == NULL) )
+        return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
+
     memcpy( p_block->p_buffer, buffer, bytes );
 
     p_block->i_dts = p_block->i_pts = p_sys->i_pts;
diff --git a/modules/codec/opus.c b/modules/codec/opus.c
index f148aa2c38b7d64783d8ed335c134f7e715cb34d..8564f6912c738170715ff3c852513fe41e1589e6 100644
--- a/modules/codec/opus.c
+++ b/modules/codec/opus.c
@@ -689,6 +689,11 @@ static block_t *Encode(encoder_t *enc, block_t *buf)
     while (sys->i_nb_samples + buf->i_nb_samples >= OPUS_FRAME_SIZE)
     {
         block_t *out_block = block_Alloc(OPUS_MAX_ENCODED_BYTES);
+        if (unlikely(out_block == NULL))
+        {
+            block_ChainRelease(result);
+            return NULL;
+        }
 
         /* add padding to beginning */
         if (sys->padding)
diff --git a/modules/codec/speex.c b/modules/codec/speex.c
index 93c5aeb7f4a8aa47fa5a74b2f8b2be07a986eca3..9cfa6324664b6fa504b4d4fa4891a719c71afc23 100644
--- a/modules/codec/speex.c
+++ b/modules/codec/speex.c
@@ -606,6 +606,9 @@ static block_t *ProcessPacket( decoder_t *p_dec, ogg_packet *p_oggpacket,
                 / 8;
 
             p_new_block = block_Alloc( i_bytes_in_speex_frame );
+            if( unlikely(p_new_block == NULL) )
+                return NULL;
+
             memset( p_new_block->p_buffer, 0xff, i_bytes_in_speex_frame );
 
             /*
@@ -635,9 +638,13 @@ static block_t *ProcessPacket( decoder_t *p_dec, ogg_packet *p_oggpacket,
                 speex_bits_write( &p_sys->bits,
                     (char*)p_block->p_buffer,
                     p_block->i_buffer - i_bytes_in_speex_frame );
+
                 p_block = block_Realloc( p_block,
                     0,
                     p_block->i_buffer-i_bytes_in_speex_frame );
+                if( unlikely(p_block == NULL) )
+                    return NULL;
+
                 *pp_block = p_block;
             }
             else
@@ -1158,6 +1165,9 @@ static block_t *Encode( encoder_t *p_enc, block_t *p_aout_buf )
         speex_bits_reset( &p_sys->bits );
 
         p_block = block_Alloc( i_out );
+        if( unlikely(p_block == NULL) )
+            break;
+
         memcpy( p_block->p_buffer, p_sys->p_buffer_out, i_out );
 
         p_block->i_length = vlc_tick_from_samples(
diff --git a/modules/codec/theora.c b/modules/codec/theora.c
index 6932f485d60544883bb29717e64badb1dc17c11a..fec555f190a928d6be4f1238fef019d70bb7b15f 100644
--- a/modules/codec/theora.c
+++ b/modules/codec/theora.c
@@ -904,6 +904,9 @@ static block_t *Encode( encoder_t *p_enc, picture_t *p_pict )
 
     /* Ogg packet to block */
     p_block = block_Alloc( oggpacket.bytes );
+    if( unlikely(p_block == NULL) )
+        return NULL;
+
     memcpy( p_block->p_buffer, oggpacket.packet, oggpacket.bytes );
     p_block->i_dts = p_block->i_pts = p_pict->date;
 
diff --git a/modules/codec/vorbis.c b/modules/codec/vorbis.c
index 7630637c0bb31d3bc20ac55e1dca61b3ad6ca29e..2528e91eec8d4ec0832da8a40f5bc1842cdacb76 100644
--- a/modules/codec/vorbis.c
+++ b/modules/codec/vorbis.c
@@ -939,6 +939,12 @@ static block_t *Encode( encoder_t *p_enc, block_t *p_aout_buf )
         {
             int i_block_size;
             p_block = block_Alloc( oggpacket.bytes );
+            if( unlikely(p_block == NULL) ) {
+                block_ChainRelease( p_chain );
+                p_chain = NULL;
+                break;
+            }
+
             memcpy( p_block->p_buffer, oggpacket.packet, oggpacket.bytes );
 
             i_block_size = vorbis_packet_blocksize( &p_sys->vi, &oggpacket );