--- modules/codec/theora.c~	2006-12-30 18:46:02.000000000 +1100
+++ modules/codec/theora.c	2006-12-30 18:53:56.000000000 +1100
@@ -218,7 +218,8 @@
         p_dec->fmt_in.p_extra =
             realloc( p_dec->fmt_in.p_extra, p_dec->fmt_in.i_extra +
                      oggpacket.bytes + 2 );
-        p_extra = p_dec->fmt_in.p_extra + p_dec->fmt_in.i_extra;
+        p_extra = p_dec->fmt_in.p_extra; 
+        p_extra += p_dec->fmt_in.i_extra;
         *(p_extra++) = oggpacket.bytes >> 8;
         *(p_extra++) = oggpacket.bytes & 0xFF;
 
@@ -595,7 +596,7 @@
 static int OpenEncoder( vlc_object_t *p_this )
 {
     encoder_t *p_enc = (encoder_t *)p_this;
-    encoder_sys_t *p_sys = p_enc->p_sys;
+    encoder_sys_t *p_sys;
     ogg_packet header;
     uint8_t *p_extra;
     vlc_value_t val;
@@ -613,6 +614,7 @@
         msg_Err( p_enc, "out of memory" );
         return VLC_EGENERIC;
     }
+    memset( p_sys, 0, sizeof(encoder_sys_t) );/*NICO_DEBUG*/
     p_enc->p_sys = p_sys;
 
     p_enc->pf_encode_video = Encode;
@@ -680,6 +682,9 @@
         p_sys->ti.aspect_denominator = 3;
     }
 
+    p_sys->ti.colorspace = OC_CS_UNSPECIFIED;
+    p_sys->ti.pixelformat = OC_PF_420;
+
     p_sys->ti.target_bitrate = p_enc->fmt_out.i_bitrate;
     p_sys->ti.quality = ((float)i_quality) * 6.3;
 
@@ -698,6 +703,7 @@
     theora_comment_init( &p_sys->tc );
 
     /* Create and store headers */
+    p_enc->fmt_out.p_extra = NULL;
     p_enc->fmt_out.i_extra = 3 * 2;
     for( i = 0; i < 3; i++ )
     {
@@ -716,6 +722,7 @@
         *(p_extra++) = header.bytes & 0xFF;
 
         memcpy( p_extra, header.packet, header.bytes );
+        if( i == 1 ) theora_comment_clear( &p_sys->tc );
     }
 
     return VLC_SUCCESS;
@@ -826,8 +833,8 @@
     encoder_t *p_enc = (encoder_t *)p_this;
     encoder_sys_t *p_sys = p_enc->p_sys;
 
-    theora_info_clear( &p_sys->ti );
-    theora_comment_clear( &p_sys->tc );
+    theora_clear( &p_sys->td );
 
     free( p_sys );
+    p_sys = NULL;/*NICO_DEBUG*/
 }
