Index: include/libroar/vio_stack.h
===================================================================
--- include/libroar/vio_stack.h	(revision 4708)
+++ include/libroar/vio_stack.h	(revision 4975)
@@ -44,4 +44,6 @@
  int next;
 
+ void (*free)(void*);
+
  struct roar_vio_calls * cur;
 
@@ -50,4 +52,5 @@
 
 int     roar_vio_open_stack    (struct roar_vio_calls * calls);
+int     roar_vio_open_stack2   (struct roar_vio_calls * calls, void (*func)(void*));
 int     roar_vio_stack_add     (struct roar_vio_calls * calls, struct roar_vio_calls * vio);
 
Index: libroar.ckport
===================================================================
--- libroar.ckport	(revision 4970)
+++ libroar.ckport	(revision 4975)
@@ -268,5 +268,6 @@
 
 # VIO Stack:
-roar_vio_open_stack		ok
+roar_vio_open_stack		legacy	Use roar_vio_open_stack2
+roar_vio_open_stack2		ok
 roar_vio_stack_add		ok
 
@@ -610,4 +611,6 @@
 roar_mm_munlock			ok
 
+roar_mm_free_retvoid		likely	Use roar_mm_free when possible (No error checking by caller)
+
 _ROAR_MLOCK			legacy	Use roar_mm_mlock
 
Index: libroar/vio_cmd.c
===================================================================
--- libroar/vio_cmd.c	(revision 4956)
+++ libroar/vio_cmd.c	(revision 4975)
@@ -62,5 +62,5 @@
 
  if ( reader != NULL )
-  state->reader.cmd = strdup(reader);
+  state->reader.cmd = roar_mm_strdup(reader);
 
  state->writer.pid = -1;
@@ -69,5 +69,5 @@
 
  if ( writer != NULL )
-  state->writer.cmd = strdup(writer);
+  state->writer.cmd = roar_mm_strdup(writer);
 
  // init state
@@ -125,8 +125,8 @@
 
  if ( state->reader.cmd != NULL )
-  free(state->reader.cmd);
+  roar_mm_free(state->reader.cmd);
 
  if ( state->writer.cmd != NULL )
-  free(state->writer.cmd);
+  roar_mm_free(state->writer.cmd);
 
  roar_vio_close(state->next);
@@ -241,5 +241,5 @@
  state->child.out = -1;
 
- state->child.cmd = strdup(command);
+ state->child.cmd = roar_mm_strdup(command);
 
  // init state
@@ -281,5 +281,5 @@
 
  if ( state->child.cmd != NULL )
-  free(state->child.cmd);
+  roar_mm_free(state->child.cmd);
 
  roar_mm_free(state);
Index: libroar/vio_dstr.c
===================================================================
--- libroar/vio_dstr.c	(revision 4964)
+++ libroar/vio_dstr.c	(revision 4975)
@@ -770,5 +770,5 @@
   return -1;
 
- if ( roar_vio_open_stack(calls) == -1 )
+ if ( roar_vio_open_stack2(calls, NULL) == -1 )
   return -1;
 
@@ -776,10 +776,10 @@
 
  if ( (def = chain->def) != NULL ) {
-  if ( (tc = malloc(sizeof(struct roar_vio_calls))) == NULL ) {
+  if ( (tc = roar_mm_malloc(sizeof(struct roar_vio_calls))) == NULL ) {
    _ret(-1);
   }
 
   if ( roar_vio_clear_calls(tc) == -1 ) {
-   free(tc);
+   roar_mm_free(tc);
    _ret(-1);
   }
@@ -809,10 +809,10 @@
 
   if ( c->need_vio ) {
-   if ( (tc = malloc(sizeof(struct roar_vio_calls))) == NULL ) {
+   if ( (tc = roar_mm_malloc(sizeof(struct roar_vio_calls))) == NULL ) {
     _ret(-1);
    }
 
    if ( roar_vio_clear_calls(tc) == -1 ) {
-    free(tc);
+    roar_mm_free(tc);
     _ret(-1);
    }
Index: libroar/vio_stack.c
===================================================================
--- libroar/vio_stack.c	(revision 4708)
+++ libroar/vio_stack.c	(revision 4975)
@@ -37,8 +37,17 @@
 
 int     roar_vio_open_stack    (struct roar_vio_calls * calls) {
+ return roar_vio_open_stack2(calls, free);
+}
+
+int     roar_vio_open_stack2   (struct roar_vio_calls * calls, void (*func)(void*)) {
  struct roar_vio_stack * self;
 
- if ( calls == NULL )
-  return -1;
+ if ( calls == NULL ) {
+  roar_err_set(ROAR_ERROR_FAULT);
+  return -1;
+ }
+
+ if ( func == NULL )
+  func = roar_mm_free_retvoid;
 
  if ( (self = roar_mm_malloc(sizeof(struct roar_vio_stack))) == NULL )
@@ -47,4 +56,6 @@
  memset(self,  0, sizeof(struct roar_vio_stack));
  memset(calls, 0, sizeof(struct roar_vio_calls));
+
+ self->free      = func;
 
  calls->inst     = self;
@@ -63,9 +74,13 @@
  struct roar_vio_stack * self;
 
- if ( calls == NULL || vio == NULL )
-  return -1;
-
- if ( (self = calls->inst) == NULL )
-  return -1;
+ if ( calls == NULL || vio == NULL ) {
+  roar_err_set(ROAR_ERROR_FAULT);
+  return -1;
+ }
+
+ if ( (self = calls->inst) == NULL ) {
+  roar_err_set(ROAR_ERROR_FAULT);
+  return -1;
+ }
 
  if ( self->next == ROAR_VIO_STACK_MAX )
@@ -81,6 +96,8 @@
  int i;
 
- if ( vio == NULL )
-  return -1;
+ if ( vio == NULL ) {
+  roar_err_set(ROAR_ERROR_FAULT);
+  return -1;
+ }
 
  if ( (self = vio->inst) == NULL )
@@ -92,5 +109,5 @@
 
   for (i = 0; i < self->next; i++)
-   free(self->calls[i]);
+   self->free(self->calls[i]);
  }
 
Index: libroaresd/esdctl.c
===================================================================
--- libroaresd/esdctl.c	(revision 4708)
+++ libroaresd/esdctl.c	(revision 4975)
@@ -69,5 +69,5 @@
 
 /* print server into to stdout */
-void esd_print_server_info( esd_server_info_t *server_info ) {
+void esd_print_server_info(esd_server_info_t *server_info ) {
  char buf[80] = "";
 
@@ -142,5 +142,5 @@
  struct roar_message    m;
 
- r = malloc(sizeof(esd_server_info_t));
+ r = roar_mm_malloc(sizeof(esd_server_info_t));
 
  if ( r == NULL )
@@ -157,15 +157,15 @@
 
  if ( roar_req(&con, &m, NULL) == -1 ) {
-  free(r);
+  roar_mm_free(r);
   return NULL;
  }
 
  if ( m.cmd != ROAR_CMD_OK ) {
-  free(r);
+  roar_mm_free(r);
   return NULL;
  }
 
  if ( roar_stream_m2s(&s, &m) == -1 ) {
-  free(r);
+  roar_mm_free(r);
   return NULL;
  }
@@ -188,6 +188,6 @@
 /* release all memory allocated for the server properties structure */
 void esd_free_server_info( esd_server_info_t *server_info ) {
- if (server_info)
-  free(server_info);
+ if (server_info != NULL)
+  roar_mm_free(server_info);
 }
 
@@ -208,5 +208,5 @@
  roar_connect_fh(con, esd);
 
- r = malloc(sizeof(esd_info_t));
+ r = roar_mm_malloc(sizeof(esd_info_t));
 
  if ( r == NULL )
@@ -234,5 +234,5 @@
    }
 
-   if ( (new_player = malloc(sizeof(esd_player_info_t))) == NULL ) {
+   if ( (new_player = roar_mm_malloc(sizeof(esd_player_info_t))) == NULL ) {
     ROAR_ERR("esd_get_all_info(*): can not alloc memory for new player! BAD");
     continue;
@@ -320,9 +320,9 @@
  player = info->player_list;
 
- while (player) {
+ while (player != NULL) {
   oplayer = player;
   player  = player->next;
 
-  free(oplayer);
+  roar_mm_free(oplayer);
  }
 
@@ -333,8 +333,8 @@
   sample  = sample->next;
 
-  free(osample);
- }
-
-  free(info);
+  roar_mm_free(osample);
+ }
+
+  roar_mm_free(info);
  }
 }
Index: roard/driver.c
===================================================================
--- roard/driver.c	(revision 4955)
+++ roard/driver.c	(revision 4975)
@@ -302,5 +302,5 @@
   return -1;
  } else {
-  driver = strdup(device);
+  driver = roar_mm_strdup(device);
 
   if ( (delm = strstr(driver, "#")) == NULL ) {
@@ -317,5 +317,5 @@
 
  if ( driver != NULL )
-  free(driver);
+  roar_mm_free(driver);
 
  return ret;
Index: roard/driver_sndio.c
===================================================================
--- roard/driver_sndio.c	(revision 4957)
+++ roard/driver_sndio.c	(revision 4975)
@@ -43,8 +43,8 @@
 }
 
-#define er() if ( self->shandle ) sio_close(self->shandle); \
-             if ( self->mhandle ) mio_close(self->mhandle); \
-             if ( self->device  ) free(self->device);       \
-             free(self);                                    \
+#define er() if ( self->shandle ) sio_close(self->shandle);   \
+             if ( self->mhandle ) mio_close(self->mhandle);   \
+             if ( self->device  ) roar_mm_free(self->device); \
+             roar_mm_free(self);                              \
              return -1
 
Index: roard/roard.c
===================================================================
--- roard/roard.c	(revision 4967)
+++ roard/roard.c	(revision 4975)
@@ -828,5 +828,5 @@
    if ( *addr == '/' ) {
     if ( (env_roar_proxy_backup = getenv("ROAR_PROXY")) != NULL ) {
-     env_roar_proxy_backup = strdup(env_roar_proxy_backup);
+     env_roar_proxy_backup = roar_mm_strdup(env_roar_proxy_backup);
      unsetenv("ROAR_PROXY");
     }
@@ -844,5 +844,5 @@
     if ( env_roar_proxy_backup != NULL ) {
      setenv("ROAR_PROXY", env_roar_proxy_backup, 0);
-     free(env_roar_proxy_backup);
+     roar_mm_free(env_roar_proxy_backup);
     }
 #else
Index: roard/sample.c
===================================================================
--- roard/sample.c	(revision 4957)
+++ roard/sample.c	(revision 4975)
@@ -77,5 +77,5 @@
   roar_buffer_free(c->data);
 
- free(c);
+ roar_mm_free(c);
 
  g_samples[id] = NULL;
