Index: libroar/basic.c
===================================================================
--- libroar/basic.c	(revision 5848)
+++ libroar/basic.c	(revision 5895)
@@ -43,5 +43,7 @@
 static int _connect_server(struct roar_connection * con, const char * server, int type, int flags, uint_least32_t timeout);
 
-int __get_daemonimage(const char ** daemonimage, enum mode * mode, const char * server) {
+int __get_daemonimage(char ** daemonimage, enum mode * mode, const char * server) {
+ const char * tmp = NULL;
+
  *daemonimage = NULL;
  *mode = NORMAL;
@@ -61,9 +63,9 @@
   } else if ( server[0] == 'd' && server[1] == ':' ) {
    server += 2;
-   *daemonimage = server;
+   tmp = server;
    *mode = NORMAL;
   } else if ( server[0] == '!' ) {
    server += 1;
-   *daemonimage = server;
+   tmp = server;
    *mode = SYSTEM;
   } else {
@@ -73,17 +75,23 @@
  }
 
+ if ( tmp == NULL || *tmp == 0 )
+  tmp = roar_libroar_get_config()->daemonimage;
+
+ // we keep this step to be compatible with older versions.
+ if ( tmp == NULL || *tmp == 0 ) {
+  tmp = roar_env_get("ROAR_DAEMONIMAGE");
+  if ( tmp != NULL ) {
+   ROAR_WARN("__get_daemonimage(*): Usage of $ROAR_DAEMONIMAGE is obsolete. Use ROAR_OPTIONS=daemonimage:...");
+  }
+ }
+
+ if ( tmp != NULL && *tmp != 0 ) {
+  *daemonimage = roar_mm_strdup(tmp);
+  return 0;
+ }
+
+ *daemonimage = roar_libroar_get_path("bin-default-daemonimage", 0, NULL, NULL);
  if ( *daemonimage == NULL )
-  *daemonimage = roar_libroar_get_config()->daemonimage;
-
- // we keep this step to be compatible with older versions.
- if ( *daemonimage == NULL || **daemonimage == 0 ) {
-  *daemonimage = roar_env_get("ROAR_DAEMONIMAGE");
-  if ( *daemonimage != NULL ) {
-   ROAR_WARN("__get_daemonimage(*): Usage of $ROAR_DAEMONIMAGE is obsolete. Use ROAR_OPTIONS=daemonimage:...");
-  }
- }
-
- if ( *daemonimage == NULL || **daemonimage == 0 )
-  *daemonimage = roar_libroar_get_path_static("bin-default-daemonimage");
+  return -1;
 
  return 0;
@@ -94,5 +102,5 @@
 static int _start_server_win32(struct roar_connection * con, const char * server, int type, int flags, uint_least32_t timeout) {
  enum mode mode = NORMAL;
- const char * daemonimage = NULL;
+ char * daemonimage = NULL;
  char buf[64];
  int port;
@@ -105,4 +113,5 @@
 
  if ( mode != NORMAL ) {
+  roar_mm_free(daemonimage);
   roar_err_set(ROAR_ERROR_NOSYS);
   return -1;
@@ -122,4 +131,5 @@
 
  if ( i == NUM_TRIES ) {
+  roar_mm_free(daemonimage);
   roar_err_set(ROAR_ERROR_LOOP);
   return -1;
@@ -141,6 +151,11 @@
   roar_err_update();
   ROAR_ERR("_start_server_win32(server='%s', ...): Can not start server: %s: %s", server, daemonimage, roar_errorstring);
-  return -1;
- }
+  err = roar_error;
+  roar_mm_free(daemonimage);
+  roar_error = err;
+  return -1;
+ }
+
+ roar_mm_free(daemonimage);
 
  snprintf(buf, sizeof(buf), "localhost:%i", port);
@@ -166,9 +181,11 @@
 static int _start_server_posix(struct roar_connection * con, const char * server, int type, int flags, uint_least32_t timeout) {
  enum mode mode = NORMAL;
- const char * daemonimage = NULL;
+ char * daemonimage = NULL;
  int socks[2];
  int r;
  char fhstr[12];
  size_t len;
+ char * bin_sh;
+ int err;
 
  if ( __get_daemonimage(&daemonimage, &mode, server) == -1 )
@@ -183,4 +200,7 @@
  if ( socketpair(AF_UNIX, SOCK_STREAM, 0, socks) == -1 ) {
   roar_err_from_errno();
+  err = roar_error;
+  roar_mm_free(daemonimage);
+  roar_error = err;
   return -1;
  }
@@ -190,6 +210,9 @@
  if ( r == -1 ) { // error!
   ROAR_ERR("_start_server(*): Can not fork: %s", roar_error2str(roar_error));
+  err = roar_error;
   close(socks[0]);
   close(socks[1]);
+  roar_mm_free(daemonimage);
+  roar_error = err;
   return -1;
  } else if ( r == 0 ) { // we are the child
@@ -211,8 +234,14 @@
      dup2(socks[1], ROAR_STDIN );
      dup2(socks[1], ROAR_STDOUT);
-     execl(roar_libroar_get_path_static("bin-sh"), roar_libroar_get_path_static("bin-sh"), "-c", daemonimage, (_LIBROAR_GOOD_CAST char*)NULL);
+     bin_sh = roar_libroar_get_path("bin-sh", 0, NULL, NULL);
+     if ( bin_sh != NULL ) {
+      execl(bin_sh, bin_sh, "-c", daemonimage, (_LIBROAR_GOOD_CAST char*)NULL);
+      roar_mm_free(bin_sh);
+     }
      execlp("sh", "sh", "-c", daemonimage, (_LIBROAR_GOOD_CAST char*)NULL);
     break;
   }
+
+  roar_mm_free(daemonimage);
 
   // we are still alive?
@@ -221,4 +250,5 @@
  } else { // we are the parent
   close(socks[1]);
+  roar_mm_free(daemonimage);
   if ( roar_vio_open_fh_socket(con->viocon, socks[0]) == -1 ) {
    close(socks[0]);
@@ -398,4 +428,5 @@
 #if !defined(ROAR_TARGET_WIN32) && !defined(ROAR_TARGET_MICROCONTROLLER)
  struct passwd * pwd;
+ char * sysconf_roarserver;
 #endif
 #ifdef ROAR_HAVE_LIBDNET
@@ -437,7 +468,11 @@
 
 #if !defined(ROAR_TARGET_WIN32) && !defined(ROAR_TARGET_MICROCONTROLLER)
- if ( (server == NULL || *server == 0) && (i = readlink(roar_libroar_get_path_static("sysconf-roarserver"), user_sock, sizeof(user_sock)-1)) != -1 ) {
-   user_sock[i] = 0;
-   server = user_sock;
+ sysconf_roarserver = roar_libroar_get_path("sysconf-roarserver", 0, NULL, NULL);
+ if ( sysconf_roarserver != NULL ) {
+  if ( (server == NULL || *server == 0) && (i = readlink(sysconf_roarserver, user_sock, sizeof(user_sock)-1)) != -1 ) {
+    user_sock[i] = 0;
+    server = user_sock;
+  }
+  roar_mm_free(sysconf_roarserver);
  }
 #endif
@@ -467,19 +502,17 @@
   if ( roar_server == NULL ) {
 #if !defined(ROAR_TARGET_WIN32) && !defined(ROAR_TARGET_MICROCONTROLLER)
-   if ( (pwd = getpwuid(getuid())) == NULL ) {
-    roar_server = roar_libroar_get_path_static("dir-nx-home");
-   } else {
+   if ( (pwd = getpwuid(getuid())) != NULL ) {
     roar_server = pwd->pw_dir;
    }
-#else
-   roar_server = "/WIN32-SUCKS";
-#endif
-  }
-
-  snprintf(user_sock, sizeof(user_sock)-1, "%s/%s", roar_server, ROAR_DEFAULT_SOCK_USER);
-  user_sock[sizeof(user_sock)-1] = 0;
-
-  if ( _connect_server(con, user_sock, ROAR_SOCKET_TYPE_UNIX, flags, timeout) == 0 )
-   return 0;
+#endif
+  }
+
+  if ( roar_server != NULL ) {
+   snprintf(user_sock, sizeof(user_sock)-1, "%s/%s", roar_server, ROAR_DEFAULT_SOCK_USER);
+   user_sock[sizeof(user_sock)-1] = 0;
+
+   if ( _connect_server(con, user_sock, ROAR_SOCKET_TYPE_UNIX, flags, timeout) == 0 )
+    return 0;
+  }
 
   if ( _connect_server(con, ROAR_DEFAULT_SOCK_GLOBAL, ROAR_SOCKET_TYPE_UNIX, flags, timeout) == 0 )
