+ int i = vlc_array_count(&name);
+ vlc_array_t module;
+ vlc_array_init(&module);
+ while(i--)
+ {
+ p_next = sout_StreamNew( p_sout, vlc_array_item_at_index(&name, i),
+ vlc_array_item_at_index(&cfg, i), p_next);
+
+ if(!p_next)
+ goto error;
+
+ if(i == vlc_array_count(&name) - 1 && pp_last)
+ *pp_last = p_next; /* last module created in the chain */
+
+ vlc_array_append(&module, p_next);
+ }
+
+ vlc_array_clear(&name);
+ vlc_array_clear(&cfg);
+ vlc_array_clear(&module);
+
+ return p_next;
+
+error:
+
+ i++; /* last module couldn't be created */
+
+ /* destroy all modules created, starting with the last one */
+ int modules = vlc_array_count(&module);
+ while(modules--)
+ sout_StreamDelete(vlc_array_item_at_index(&module, modules));
+ vlc_array_clear(&module);
+
+ /* then destroy all names and config which weren't destroyed by
+ * sout_StreamDelete */
+ while(i--)
+ {
+ free(vlc_array_item_at_index(&name, i));
+ config_ChainDestroy(vlc_array_item_at_index(&cfg, i));
+ }
+ vlc_array_clear(&name);
+ vlc_array_clear(&cfg);
+
+ return NULL;