diff --git a/celt/celt.c b/celt/celt.c
index 4ddba9e1c12f394e4c11a9407b749c2ce1ceb8b7..06cc4cc5c4b8b1d0a78d02a0f84e8b327ad74ff9 100644
--- a/celt/celt.c
+++ b/celt/celt.c
@@ -2448,6 +2448,8 @@ static void celt_decode_lost(CELTDecoder * OPUS_RESTRICT st, opus_val16 * OPUS_R
       compute_inv_mdcts(st->mode, 0, freq, out_syn, overlap_mem, C, LM);
    } else {
       /* Pitch-based PLC */
+      VARDECL(opus_val32, e);
+
       if (st->loss_count == 0)
       {
          opus_val16 pitch_buf[DECODE_BUFFER_SIZE>>1];
@@ -2465,16 +2467,14 @@ static void celt_decode_lost(CELTDecoder * OPUS_RESTRICT st, opus_val16 * OPUS_R
          fade = QCONST16(.8f,15);
       }
 
+      ALLOC(e, MAX_PERIOD+2*st->mode->overlap, opus_val32);
       c=0; do {
-         VARDECL(opus_val32, e);
          opus_val16 exc[MAX_PERIOD];
          opus_val32 ac[LPC_ORDER+1];
          opus_val16 decay = 1;
          opus_val32 S1=0;
          opus_val16 mem[LPC_ORDER]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
 
-         ALLOC(e, MAX_PERIOD+2*st->mode->overlap, opus_val32);
-
          offset = MAX_PERIOD-pitch_index;
          for (i=0;i<MAX_PERIOD;i++)
             exc[i] = ROUND16(out_mem[c][i], SIG_SHIFT);
@@ -2708,6 +2708,13 @@ int celt_decode_with_ec(CELTDecoder * OPUS_RESTRICT st, const unsigned char *dat
    if (effEnd > st->mode->effEBands)
       effEnd = st->mode->effEBands;
 
+   if (data == NULL || len<=1)
+   {
+      celt_decode_lost(st, pcm, N, LM);
+      RESTORE_STACK;
+      return frame_size/st->downsample;
+   }
+
    ALLOC(freq, IMAX(CC,C)*N, celt_sig); /**< Interleaved signal MDCTs */
    ALLOC(X, C*N, celt_norm);   /**< Interleaved normalised MDCTs */
    ALLOC(bandE, st->mode->nbEBands*C, celt_ener);
@@ -2720,13 +2727,6 @@ int celt_decode_with_ec(CELTDecoder * OPUS_RESTRICT st, const unsigned char *dat
          X[c*N+i] = 0;
    while (++c<C);
 
-   if (data == NULL || len<=1)
-   {
-      celt_decode_lost(st, pcm, N, LM);
-      RESTORE_STACK;
-      return frame_size/st->downsample;
-   }
-
    if (dec == NULL)
    {
       ec_dec_init(&_dec,(unsigned char*)data,len);