Index: libroar/vio.c
===================================================================
--- libroar/vio.c	(revision 5381)
+++ libroar/vio.c	(revision 5388)
@@ -53,5 +53,5 @@
  memset((void*)calls, 0, sizeof(struct roar_vio_calls));
  calls->flags = ROAR_VIO_FLAGS_NONE;
- calls->refc  = 0;
+ calls->refc  = 1;
 
  return 0;
@@ -202,18 +202,35 @@
 }
 
-int     roar_vio_close    (struct roar_vio_calls * vio) {
+
+int     roar_vio_ref      (struct roar_vio_calls * vio) {
+ if ( vio == NULL ) {
+  roar_err_set(ROAR_ERROR_FAULT);
+  return -1;
+ }
+
+ vio->refc++;
+
+ return 0;
+}
+
+int     roar_vio_unref    (struct roar_vio_calls * vio) {
  int ret;
 
- ROAR_DBG("roar_vio_close(vio=%p) = ?", vio);
-
- if ( vio == NULL ) {
-  roar_err_set(ROAR_ERROR_FAULT);
-  return -1;
- }
-
- if ( vio->close == NULL ) {
+ ROAR_DBG("roar_vio_unref(vio=%p) = ?", vio);
+
+ if ( vio == NULL ) {
+  roar_err_set(ROAR_ERROR_FAULT);
+  return -1;
+ }
+
+ if ( vio->refc == 1 && vio->close == NULL ) {
   roar_err_set(ROAR_ERROR_NOSYS);
   return -1;
  }
+
+ vio->refc--;
+
+ if ( vio->refc )
+  return 0;
 
  roar_err_clear_all();
@@ -221,4 +238,7 @@
  roar_err_update();
 
+ if ( vio->flags & ROAR_VIO_FLAGS_FREESELF )
+  roar_mm_free(vio);
+
  return ret;
 }
@@ -257,4 +277,6 @@
 
  memset((void*)calls, 0, sizeof(struct roar_vio_calls));
+ calls->flags    = ROAR_VIO_FLAGS_NONE;
+ calls->refc     = 1;
 
  calls->read     = roar_vio_basic_read;
@@ -642,4 +664,6 @@
 
  memset((void*)calls, 0, sizeof(struct roar_vio_calls));
+ calls->flags    = ROAR_VIO_FLAGS_NONE;
+ calls->refc     = 1;
 
  calls->read     = roar_vio_pass_read;
Index: libroar/vio_bio.c
===================================================================
--- libroar/vio_bio.c	(revision 5381)
+++ libroar/vio_bio.c	(revision 5388)
@@ -42,4 +42,6 @@
 
  memset(calls, 0, sizeof(struct roar_vio_calls));
+ calls->flags    = ROAR_VIO_FLAGS_NONE;
+ calls->refc     = 1;
 
  calls->read     = roar_vio_bio_read;
Index: libroar/vio_buffer.c
===================================================================
--- libroar/vio_buffer.c	(revision 5381)
+++ libroar/vio_buffer.c	(revision 5388)
@@ -59,4 +59,6 @@
 
  memset(calls, 0, sizeof(struct roar_vio_calls));
+ calls->flags    = ROAR_VIO_FLAGS_NONE;
+ calls->refc     = 1;
 
  calls->inst     = self;
Index: libroar/vio_buffer_store.c
===================================================================
--- libroar/vio_buffer_store.c	(revision 5381)
+++ libroar/vio_buffer_store.c	(revision 5388)
@@ -50,4 +50,6 @@
 
  memset(calls, 0, sizeof(struct roar_vio_calls));
+ calls->flags    = ROAR_VIO_FLAGS_NONE;
+ calls->refc     = 1;
 
  if ( inst != NULL )
Index: libroar/vio_cmd.c
===================================================================
--- libroar/vio_cmd.c	(revision 5381)
+++ libroar/vio_cmd.c	(revision 5388)
@@ -54,4 +54,6 @@
  // clear all
  memset(calls, 0, sizeof(struct roar_vio_calls));
+ calls->flags    = ROAR_VIO_FLAGS_NONE;
+ calls->refc     = 1;
  memset(state, 0, sizeof(struct roar_vio_cmd_state));
 
@@ -233,4 +235,6 @@
  // clear all
  memset(calls, 0, sizeof(struct roar_vio_calls));
+ calls->flags    = ROAR_VIO_FLAGS_NONE;
+ calls->refc     = 1;
  memset(state, 0, sizeof(struct roar_vio_2popen_state));
 
Index: libroar/vio_dstr.c
===================================================================
--- libroar/vio_dstr.c	(revision 5381)
+++ libroar/vio_dstr.c	(revision 5388)
@@ -411,4 +411,23 @@
 }
 
+struct roar_vio_calls * roar_vio_open_dstr_simple_new(const char * dstr, int o_flags) {
+ struct roar_vio_calls * ret = roar_mm_malloc(sizeof(struct roar_vio_calls));
+ int err;
+
+ if ( ret == NULL )
+  return NULL;
+
+ if ( roar_vio_open_dstr_simple(ret, dstr, o_flags) == -1 ) {
+  err = roar_error;
+  roar_mm_free(ret);
+  roar_error = err;
+  return NULL;
+ }
+
+ ret->flags |= ROAR_VIO_FLAGS_FREESELF;
+
+ return ret;
+}
+
 int     roar_vio_open_dstr    (struct roar_vio_calls * calls, const char * dstr, struct roar_vio_defaults * def, int dnum) {
  return roar_vio_open_dstr_vio(calls, dstr, def, dnum, NULL);
Index: libroar/vio_jumbo.c
===================================================================
--- libroar/vio_jumbo.c	(revision 5381)
+++ libroar/vio_jumbo.c	(revision 5388)
@@ -53,4 +53,6 @@
 
  memset(calls, 0, sizeof(struct roar_vio_calls));
+ calls->flags    = ROAR_VIO_FLAGS_NONE;
+ calls->refc     = 1;
  calls->inst     = self;
  calls->close    = roar_vio_jumbo_close;
Index: libroar/vio_misc.c
===================================================================
--- libroar/vio_misc.c	(revision 5381)
+++ libroar/vio_misc.c	(revision 5388)
@@ -106,4 +106,6 @@
 
  memset(calls, 0, sizeof(struct roar_vio_calls));
+ calls->flags    = ROAR_VIO_FLAGS_NONE;
+ calls->refc     = 1;
  calls->read     = roar_vio_misc_read;
  calls->write    = roar_vio_misc_write;
Index: libroar/vio_pipe.c
===================================================================
--- libroar/vio_pipe.c	(revision 5381)
+++ libroar/vio_pipe.c	(revision 5388)
@@ -125,4 +125,6 @@
 
  memset(s, 0, sizeof(struct roar_vio_calls));
+ s->flags    = ROAR_VIO_FLAGS_NONE;
+ s->refc     = 1;
 
  s->close    = roar_vio_pipe_close;
Index: libroar/vio_rtp.c
===================================================================
--- libroar/vio_rtp.c	(revision 5381)
+++ libroar/vio_rtp.c	(revision 5388)
@@ -110,4 +110,6 @@
 
  memset(calls, 0, sizeof(struct roar_vio_calls));
+ calls->flags    = ROAR_VIO_FLAGS_NONE;
+ calls->refc     = 1;
 
  calls->inst               = self;
Index: libroar/vio_stack.c
===================================================================
--- libroar/vio_stack.c	(revision 5381)
+++ libroar/vio_stack.c	(revision 5388)
@@ -56,4 +56,6 @@
  memset(self,  0, sizeof(struct roar_vio_stack));
  memset(calls, 0, sizeof(struct roar_vio_calls));
+ calls->flags    = ROAR_VIO_FLAGS_NONE;
+ calls->refc     = 1;
 
  self->free      = func;
Index: libroar/vio_stdio.c
===================================================================
--- libroar/vio_stdio.c	(revision 5381)
+++ libroar/vio_stdio.c	(revision 5388)
@@ -42,4 +42,6 @@
 
  memset(calls, 0, sizeof(struct roar_vio_calls));
+ calls->flags    = ROAR_VIO_FLAGS_NONE;
+ calls->refc     = 1;
 
  calls->read  = roar_vio_stdio_read;
Index: libroar/vio_tantalos.c
===================================================================
--- libroar/vio_tantalos.c	(revision 5381)
+++ libroar/vio_tantalos.c	(revision 5388)
@@ -97,5 +97,5 @@
    return 0;
 
-  memset(calls, 0, sizeof(*calls));
+  memset(calls, 0, sizeof(struct roar_vio_calls));
  }
 
Index: libroar/vio_zlib.c
===================================================================
--- libroar/vio_zlib.c	(revision 5381)
+++ libroar/vio_zlib.c	(revision 5388)
@@ -538,4 +538,6 @@
 
  memset(calls, 0, sizeof(struct roar_vio_calls));
+ calls->flags      = ROAR_VIO_FLAGS_NONE;
+ calls->refc       = 1;
 
  calls->inst       = self;
