Index: libroar/caps.c
===================================================================
--- libroar/caps.c	(revision 5961)
+++ libroar/caps.c	(revision 6029)
@@ -48,12 +48,16 @@
  size_t needlen = 4;
 
- if ( mes == NULL || caps == NULL )
-  return -1;
+ if ( mes == NULL || caps == NULL ) {
+  roar_err_set(ROAR_ERROR_FAULT);
+  return -1;
+ }
 
  needlen += caps->len;
 
  if ( needlen > sizeof(mes->data) ) {
-  if ( data == NULL )
+  if ( data == NULL ) {
+   roar_err_set(ROAR_ERROR_FAULT);
    return -1;
+  }
 
   if ( (*data = roar_mm_malloc(needlen)) == NULL )
@@ -82,6 +86,8 @@
  char * datap;
 
- if ( mes == NULL || caps == NULL )
-  return -1;
+ if ( mes == NULL || caps == NULL ) {
+  roar_err_set(ROAR_ERROR_FAULT);
+  return -1;
+ }
 
  if ( data != NULL ) {
@@ -92,6 +98,13 @@
 
  // versin check.
- if ( datap[0] != 0 || mes->datalen < 4 )
-  return -1;
+ if ( datap[0] != 0 ) {
+  roar_err_set(ROAR_ERROR_NSVERSION);
+  return -1;
+ }
+
+ if ( mes->datalen < 4 ) {
+  roar_err_set(ROAR_ERROR_PROTO);
+  return -1;
+ }
 
  memset(caps, 0, sizeof(struct roar_caps));
@@ -132,6 +145,8 @@
   flags |= ROAR_CF_REQUEST;
 
- if ( (flags & ROAR_CF_REQUEST) && out == NULL )
-  return -1;
+ if ( (flags & ROAR_CF_REQUEST) && out == NULL ) {
+  roar_err_set(ROAR_ERROR_FAULT);
+  return -1;
+ }
 
  if ( in != NULL )
@@ -179,5 +194,5 @@
  if ( mes.cmd != ROAR_CMD_OK ) {
   if ( data != NULL )
-   roar_mm_free(data);
+   roar_mm_free_noerror(data);
   return -1;
  }
@@ -185,5 +200,5 @@
  if ( roar_caps_from_msg(&caps, &mes, data) == -1 ) {
   if ( data != NULL )
-   roar_mm_free(data);
+   roar_mm_free_noerror(data);
   return -1;
  }
@@ -193,4 +208,5 @@
   if ( data != NULL )
    roar_mm_free(data);
+  roar_err_set(ROAR_ERROR_PROTO);
   return -1;
  }
@@ -200,5 +216,5 @@
   if ( *out == NULL ) {
    if ( data != NULL )
-    roar_mm_free(data);
+    roar_mm_free_noerror(data);
    return -1;
   }
@@ -237,5 +253,5 @@
 
  if ( ret->stds == NULL ) {
-  roar_mm_free(ret);
+  roar_mm_free_noerror(ret);
   return NULL;
  }
Index: libroar/random.c
===================================================================
--- libroar/random.c	(revision 5961)
+++ libroar/random.c	(revision 6029)
@@ -198,6 +198,8 @@
   return 0;
 
- if ( buffer == NULL )
+ if ( buffer == NULL ) {
+  roar_err_set(ROAR_ERROR_FAULT);
   return -1;
+ }
 
  roar_random_init();
@@ -224,4 +226,5 @@
 #endif
   default:
+    roar_err_set(ROAR_ERROR_NOENT);
     return -1;
    break;
@@ -239,5 +242,5 @@
  if ( locked ) {
   if ( roar_mm_mlock(ret, len) == -1 ) {
-   roar_mm_free(ret);
+   roar_mm_free_noerror(ret);
    return NULL;
   }
@@ -245,5 +248,5 @@
 
  if ( roar_random_gen(ret, len, quality) == -1 ) {
-  roar_mm_free(ret);
+  roar_mm_free_noerror(ret);
   return NULL;
  }
Index: libroar/serverinfo.c
===================================================================
--- libroar/serverinfo.c	(revision 5961)
+++ libroar/serverinfo.c	(revision 6029)
@@ -174,6 +174,8 @@
  char * mesdata;
 
- if ( mes == NULL || info == NULL )
+ if ( mes == NULL || info == NULL ) {
+  roar_err_set(ROAR_ERROR_FAULT);
   return -1;
+ }
 
  _add(ROAR_ITST_VERSION, version);
@@ -193,6 +195,8 @@
 
  if ( needlen > LIBROAR_BUFFER_MSGDATA ) {
-  if ( data == NULL )
+  if ( data == NULL ) {
+   roar_err_set(ROAR_ERROR_MSGSIZE);
    return -1;
+  }
 
   mesdata = roar_mm_malloc(needlen);
@@ -250,6 +254,8 @@
  ROAR_DBG("roar_server_info(mes=%p{.datalen=%llu) = ?", mes, (long long unsigned int)mes->datalen);
 
- if ( mes == NULL )
-  return NULL;
+ if ( mes == NULL ) {
+  roar_err_set(ROAR_ERROR_FAULT);
+  return NULL;
+ }
 
  if ( data == NULL ) {
@@ -264,16 +270,22 @@
 
  // some basic texts like version:
- if ( mes->datalen < needlen )
-  return NULL;
-
- ROAR_DBG("roar_server_info(mes=%p) = ?", mes);
-
- if ( mesdata[0] != 0 ) /* version */
-  return NULL;
-
- ROAR_DBG("roar_server_info(mes=%p) = ?", mes);
-
- if ( mesdata[1] != 0 ) /* reserved */
-  return NULL;
+ if ( mes->datalen < needlen ) {
+  roar_err_set(ROAR_ERROR_PROTO);
+  return NULL;
+ }
+
+ ROAR_DBG("roar_server_info(mes=%p) = ?", mes);
+
+ if ( mesdata[0] != 0 ) { /* version */
+  roar_err_set(ROAR_ERROR_NSVERSION);
+  return NULL;
+ }
+
+ ROAR_DBG("roar_server_info(mes=%p) = ?", mes);
+
+ if ( mesdata[1] != 0 ) { /* reserved */
+  roar_err_set(ROAR_ERROR_PROTO);
+  return NULL;
+ }
 
  ROAR_DBG("roar_server_info(mes=%p) = ?", mes);
@@ -286,6 +298,8 @@
 
  // return error if our index buffer is too short.
- if ( idx > (sizeof(iebuf)/sizeof(*iebuf)) )
-  return NULL;
+ if ( idx > (sizeof(iebuf)/sizeof(*iebuf)) ) {
+  roar_err_set(ROAR_ERROR_MSGSIZE);
+  return NULL;
+ }
 
  ROAR_DBG("roar_server_info(mes=%p) = ?", mes);
@@ -296,6 +310,8 @@
 
  // recheck if we have a complet index.
- if ( mes->datalen < needlen )
-  return NULL;
+ if ( mes->datalen < needlen ) {
+  roar_err_set(ROAR_ERROR_PROTO);
+  return NULL;
+ }
 
  ROAR_DBG("roar_server_info(mes=%p) = ?", mes);
@@ -321,6 +337,8 @@
 
  // recheck if we have all the data...
- if ( mes->datalen < needlen )
-  return NULL;
+ if ( mes->datalen < needlen ) {
+  roar_err_set(ROAR_ERROR_PROTO);
+  return NULL;
+ }
 
  ROAR_DBG("roar_server_info(mes=%p) = ?", mes);
Index: libroar/vio_misc.c
===================================================================
--- libroar/vio_misc.c	(revision 5961)
+++ libroar/vio_misc.c	(revision 6029)
@@ -39,6 +39,8 @@
  struct roar_vio_misc * self = vio->inst;
 
- if ( self->read == NULL )
+ if ( self->read == NULL ) {
+  roar_err_set(ROAR_ERROR_NOSYS);
   return -1;
+ }
 
  return self->read(buf, count, vio, self);
@@ -48,6 +50,8 @@
  struct roar_vio_misc * self = vio->inst;
 
- if ( self->write == NULL )
+ if ( self->write == NULL ) {
+  roar_err_set(ROAR_ERROR_RO);
   return -1;
+ }
 
  return self->write(buf, count, vio, self);
@@ -74,6 +78,8 @@
  switch (cmd) {
   case ROAR_VIO_CTL_GET_NAME:
-    if ( data == NULL )
+    if ( data == NULL ) {
+     roar_err_set(ROAR_ERROR_FAULT);
      return -1;
+    }
 
     *(const char**)data = self->name;
@@ -91,8 +97,10 @@
      return 0;
 
+    roar_err_set(ROAR_ERROR_NOSYS);
     return -1;
    break; 
  }
 
+ roar_err_set(ROAR_ERROR_BADRQC);
  return -1;
 }
@@ -104,6 +112,8 @@
 
 int     roar_vio_open_misc    (struct roar_vio_calls * calls, const struct roar_vio_misc * callbacks) {
- if ( calls == NULL || callbacks == NULL )
+ if ( calls == NULL || callbacks == NULL ) {
+  roar_err_set(ROAR_ERROR_FAULT);
   return -1;
+ }
 
  memset(calls, 0, sizeof(struct roar_vio_calls));
@@ -173,6 +183,8 @@
  size_t i;
 
- if ( calls == NULL || name == NULL )
+ if ( calls == NULL || name == NULL ) {
+  roar_err_set(ROAR_ERROR_FAULT);
   return -1;
+ }
 
  for (i = 0; i < (sizeof(libroar_vio_miscs)/sizeof(*libroar_vio_miscs)); i++)
@@ -180,4 +192,5 @@
    return roar_vio_open_misc(calls, &(libroar_vio_miscs[i]));
 
+ roar_err_set(ROAR_ERROR_NOENT);
  return -1;
 }
Index: libroar/vio_winsock.c
===================================================================
--- libroar/vio_winsock.c	(revision 5961)
+++ libroar/vio_winsock.c	(revision 6029)
@@ -48,9 +48,21 @@
 
 ssize_t roar_vio_winsock_read    (struct roar_vio_calls * vio, void *buf, size_t count) {
- return recv(_get_fh(vio), buf, count, 0);
+ ssize_t ret;
+
+ roar_err_clear_all();
+ ret = recv(_get_fh(vio), buf, count, 0);
+ roar_err_update();
+
+ return ret;
 }
 
 ssize_t roar_vio_winsock_write   (struct roar_vio_calls * vio, void *buf, size_t count) {
- return send(_get_fh(vio), buf, count, 0);
+ ssize_t ret;
+
+ roar_err_clear_all();
+ ret = send(_get_fh(vio), buf, count, 0);
+ roar_err_update();
+
+ return ret;
 }
 
@@ -70,6 +82,8 @@
  switch (cmd) {
   case ROAR_VIO_CTL_GET_NAME:
-    if ( data == NULL )
+    if ( data == NULL ) {
+     roar_err_set(ROAR_ERROR_FAULT);
      return -1;
+    }
 
     *(char**)data = "winsock";
@@ -88,5 +102,7 @@
    break;
   case ROAR_VIO_CTL_ACCEPT:
+    roar_err_clear_all();
     tmp = accept(_get_fh(vio), NULL, 0);
+    roar_err_update();
     if ( tmp == -1 )
      return -1;
@@ -113,6 +129,8 @@
     }
 
-    if ( tmp != 0 ) /* we currently only support R and W shutdowns */
+    if ( tmp != 0 ) { /* we currently only support R and W shutdowns */
+     roar_err_set(ROAR_ERROR_NOSYS);
      return -1;
+    }
 
     if ( s_r && s_w ) {
