Index: include/libroar/pinentry.h
===================================================================
--- include/libroar/pinentry.h	(revision 5381)
+++ include/libroar/pinentry.h	(revision 5754)
@@ -49,5 +49,5 @@
 };
 
-int roar_pinentry_open (struct roar_pinentry * pe, int flags, char * display, char * tty, char * term);
+int roar_pinentry_open (struct roar_pinentry * pe, int flags, const char * display, const char * tty, const char * term);
 int roar_pinentry_simple_open(struct roar_pinentry * pe);
 int roar_pinentry_close(struct roar_pinentry * pe);
Index: libroar/basic.c
===================================================================
--- libroar/basic.c	(revision 5745)
+++ libroar/basic.c	(revision 5754)
@@ -69,5 +69,5 @@
  // we keep this step to be compatible with older versions.
  if ( daemonimage == NULL || *daemonimage == 0 ) {
-  daemonimage = getenv("ROAR_DAEMONIMAGE");
+  daemonimage = roar_env_get("ROAR_DAEMONIMAGE");
   if ( daemonimage != NULL ) {
    ROAR_WARN("_start_server(*): Usage of $ROAR_DAEMONIMAGE is obsolete. Use ROAR_OPTIONS=daemonimage:...");
@@ -275,5 +275,5 @@
 #if defined(ROAR_HAVE_UNIX)
  char user_sock[128];
- char * roar_server;
+ const char * roar_server;
 #endif
 #if defined(ROAR_HAVE_LIBSLP) || !defined(ROAR_TARGET_MICROCONTROLLER)
@@ -309,5 +309,5 @@
 
  if ( server == NULL || *server == 0 )
-  server = getenv("ROAR_SERVER");
+  server = roar_env_get("ROAR_SERVER");
 
 #ifdef ROAR_HAVE_LIBX11
@@ -344,5 +344,5 @@
 #ifdef ROAR_HAVE_UNIX
 #ifndef ROAR_TARGET_MICROCONTROLLER
-  roar_server = getenv("HOME");
+  roar_server = roar_env_get("HOME");
 #else
   roar_server = NULL;
Index: libroar/config.c
===================================================================
--- libroar/config.c	(revision 5747)
+++ libroar/config.c	(revision 5754)
@@ -76,13 +76,17 @@
  struct roar_libroar_config * config = roar_libroar_get_config_ptr();
  static int inited = 0;
- char * next;
+ const char * next;
+ char * buf;
 
  if ( !inited ) {
   inited++; // we do this early so we can use ROAR_{DBG,INFO,WARN,ERR}() in roar_libroar_config_parse().
 
-  next = getenv("ROAR_OPTIONS");
+  next = roar_env_get("ROAR_OPTIONS");
 
   if ( next != NULL ) {
-   roar_libroar_config_parse(next, " ");
+   if ( (buf = roar_mm_strdup(next)) != NULL ) {
+    roar_libroar_config_parse(buf, " ");
+    roar_mm_free(buf);
+   }
   }
  }
Index: libroar/enumdev.c
===================================================================
--- libroar/enumdev.c	(revision 5381)
+++ libroar/enumdev.c	(revision 5754)
@@ -115,5 +115,5 @@
   _add(new);
 
-  new = getenv("ROAR_SERVER");
+  new = roar_env_get("ROAR_SERVER");
   _add(new);
 
@@ -126,7 +126,7 @@
 #endif
 
-  new = getenv("SSH_CLIENT");
+  new = roar_env_get("SSH_CLIENT");
   if ( new == NULL )
-   new = getenv("SSH_CONNECTION");
+   new = roar_env_get("SSH_CONNECTION");
 
   if ( new != NULL ) {
Index: libroar/env.c
===================================================================
--- libroar/env.c	(revision 5752)
+++ libroar/env.c	(revision 5754)
@@ -86,5 +86,5 @@
 
 const char * roar_env_get_home(int level) {
- const char * home = getenv("HOME");
+ const char * home = roar_env_get("HOME");
 
  (void)level;
Index: libroar/file.c
===================================================================
--- libroar/file.c	(revision 5381)
+++ libroar/file.c	(revision 5754)
@@ -86,5 +86,5 @@
  const char * k;
 
- if ( (k = getenv("CDDA_DEVICE")) != NULL )
+ if ( (k = roar_env_get("CDDA_DEVICE")) != NULL )
   return k;
 
Index: libroar/pinentry.c
===================================================================
--- libroar/pinentry.c	(revision 5619)
+++ libroar/pinentry.c	(revision 5754)
@@ -45,5 +45,5 @@
 #endif
 
-int roar_pinentry_open (struct roar_pinentry * pe, int flags, char * display, char * tty, char * term) {
+int roar_pinentry_open (struct roar_pinentry * pe, int flags, const char * display, const char * tty, const char * term) {
 #ifdef _CAN_OPERATE
  int in[2], out[2];
@@ -57,5 +57,5 @@
 
  if ( display == NULL )
-  display = getenv("DISPLAY");
+  display = roar_env_get("DISPLAY");
 
  if ( display == NULL )
@@ -73,5 +73,5 @@
 
  if ( term == NULL )
-  term = getenv("TERM");
+  term = roar_env_get("TERM");
 
  if ( term == NULL )
Index: libroar/socket.c
===================================================================
--- libroar/socket.c	(revision 5745)
+++ libroar/socket.c	(revision 5754)
@@ -401,5 +401,5 @@
 
 int roar_socket_connect (int type, const char * host, int port) {
- char * proxy_type = getenv("ROAR_PROXY");
+ const char * proxy_type = roar_env_get("ROAR_PROXY");
 
  ROAR_DBG("roar_socket_connect(host='%s', port=%i) = ?", host, port);
@@ -874,8 +874,8 @@
  int    proxy_port = -1;
  char   proxy_host[ROAR_SOCKET_MAX_HOSTNAMELEN];
- char * proxy_addr = NULL;
+ const char * proxy_addr = NULL;
  int    i;
  int    fh = -1;
- char * user = NULL, * pw = NULL, * opts = NULL;
+ const char * user = NULL, * pw = NULL, * opts = NULL;
  char * sep;
  int    no_fh = 0;
@@ -895,5 +895,5 @@
 
  if ( user == NULL )
-  user = getenv("USER");
+  user = roar_env_get("USER");
 
  // TODO: change this so we support listen() proxys (ssh -R)
@@ -902,5 +902,5 @@
 
  if ( !strncmp(proxy_type, "socks", 5) ) {
-  proxy_addr = getenv("socks_proxy");
+  proxy_addr = roar_env_get("socks_proxy");
 
   proxy_port = 9050; // TOR's default port
@@ -908,6 +908,6 @@
   proxy_port = 8080;
 
-  if ( (proxy_addr = getenv("http_proxy")) == NULL )
-   proxy_addr = getenv("https_proxy");
+  if ( (proxy_addr = roar_env_get("http_proxy")) == NULL )
+   proxy_addr = roar_env_get("https_proxy");
 
   if ( proxy_addr == NULL )
@@ -918,5 +918,5 @@
  } else if ( !strncmp(proxy_type, "ssh", 3) ) {
   proxy_port = 22;
-  proxy_addr = getenv("ssh_proxy");
+  proxy_addr = roar_env_get("ssh_proxy");
   no_fh      = 1;
  }
@@ -1105,5 +1105,5 @@
 #ifdef ROAR_HAVE_BIN_SSH
 static int roar_socket_open_ssh    (int mode, int fh, const char * host, int port, const char * user, const char * pw, const char * opts) {
- char * proxy_addr = getenv("ssh_proxy");
+ const char * proxy_addr = roar_env_get("ssh_proxy");
  char * sep;
  char   cmd[1024] = {0}, rcmd[1024] = {0};
Index: libroaresd/esdbasic.c
===================================================================
--- libroaresd/esdbasic.c	(revision 5381)
+++ libroaresd/esdbasic.c	(revision 5754)
@@ -49,5 +49,5 @@
 
  if ( host == NULL )
-  host = getenv("ESPEAKER");
+  host = roar_env_get("ESPEAKER");
 
  if ( roar_simple_connect(&con, (char*) host, NULL) == -1 ) {
Index: libroaross/libroaross.c
===================================================================
--- libroaross/libroaross.c	(revision 5543)
+++ libroaross/libroaross.c	(revision 5754)
@@ -382,7 +382,7 @@
 }
 
-static struct session * _open_session (char * server, char * name) {
+static struct session * _open_session (const char * server, const char * name) {
  struct session * ses = &_session;
- int new_session = getenv("ROAR_OSS_NEW_SESSION") == NULL ? 0 : 1;
+ int new_session = roar_env_get("ROAR_OSS_NEW_SESSION") == NULL ? 0 : 1;
 
  ROAR_DBG("_open_session(server='%s', name='%s') = ?", server, name);
@@ -400,5 +400,5 @@
 
   if ( name == NULL )
-   name = getenv("ROAR_OSS_CLIENT_NAME");
+   name = roar_env_get("ROAR_OSS_CLIENT_NAME");
 
   if ( name == NULL )
@@ -415,5 +415,5 @@
 
   if ( !new_session ) {
-   if ( getenv("ROAR_OSS_KEEP_SESSION") != NULL )
+   if ( roar_env_get("ROAR_OSS_KEEP_SESSION") != NULL )
     ses->refc++;
   }
Index: libroarpulse/libroarpulse.c
===================================================================
--- libroarpulse/libroarpulse.c	(revision 5381)
+++ libroarpulse/libroarpulse.c	(revision 5754)
@@ -124,5 +124,5 @@
 
  if ( server == NULL )
-  server = getenv("PULSE_SERVER");
+  server = roar_env_get("PULSE_SERVER");
 
  if ( server == NULL ) {
Index: libroarpulse/util.c
===================================================================
--- libroarpulse/util.c	(revision 5381)
+++ libroarpulse/util.c	(revision 5754)
@@ -73,5 +73,5 @@
 /** Return the current username in the specified string buffer. */
 char *pa_get_user_name(char *s, size_t l) {
- char * user = NULL;
+ const char * user = NULL;
 
  if ( s == NULL ) {
@@ -82,9 +82,9 @@
 
  if ( user == NULL )
-  user = getenv("USER");
+  user = roar_env_get("USER");
  if ( user == NULL )
-  user = getenv("LOGNAME");
+  user = roar_env_get("LOGNAME");
  if ( user == NULL )
-  user = getenv("USERNAME");
+  user = roar_env_get("USERNAME");
 
 #ifdef ROAR_HAVE_GETUID
@@ -126,12 +126,6 @@
 /** Return the home directory of the current user */
 char *pa_get_home_dir(char *s, size_t l) {
- char * home = getenv("HOME");
-
- if ( home == NULL )
+ if ( roar_env_render_path_r(s, l, "~/") == -1 )
   return NULL;
-
- strncpy(s, home, l);
-
- s[l-1] = 0;
 
  return s;
Index: libroarrsound/libroarrsound.c
===================================================================
--- libroarrsound/libroarrsound.c	(revision 5381)
+++ libroarrsound/libroarrsound.c	(revision 5754)
@@ -244,5 +244,5 @@
 
 static int libroarrsound_connect (struct libroarrsound * self) {
- char * host;
+ const char * host;
 
  if ( self->flags & LIBROARRSOUND_FLAGS_CONNECTED )
@@ -252,5 +252,5 @@
 
  if ( host == NULL )
-  host = getenv("RSD_SERVER");
+  host = roar_env_get("RSD_SERVER");
 
  // FIXME: we currently ignore the port. :(
Index: libroarsndio/libroarsndio.c
===================================================================
--- libroarsndio/libroarsndio.c	(revision 5381)
+++ libroarsndio/libroarsndio.c	(revision 5754)
@@ -142,7 +142,7 @@
  if ( name == NULL ) {
   if ( is_midi ) {
-   name = getenv("MIDIDEVICE");
+   name = roar_env_get("MIDIDEVICE");
   } else {
-   name = getenv("AUDIODEVICE");
+   name = roar_env_get("AUDIODEVICE");
   }
  }
Index: roarclients/roarmonhttp.c
===================================================================
--- roarclients/roarmonhttp.c	(revision 5536)
+++ roarclients/roarmonhttp.c	(revision 5754)
@@ -239,4 +239,6 @@
  int    i;
  const char * k, * v;
+ const char * qs;
+ char * qs_buf;
  char * c;
  char * sp0 = NULL, * sp1 = NULL;
@@ -292,7 +294,10 @@
  }
 
- c = getenv("QUERY_STRING");
+ qs = roar_env_get("QUERY_STRING");
+ if ( qs == NULL )
+  qs = "";
+ c = qs_buf = roar_mm_strdup(qs);
  if ( c == NULL )
-  c = "";
+  return 1;
 
  c = roar_mm_strtok_r(c, "&", &sp0);
@@ -336,4 +341,6 @@
  }
 
+ roar_mm_free(qs_buf);
+
  if ( roar_simple_connect(&con, server, "roarmonhttp") == -1 ) {
   return 10;
Index: roard/driver_dmx.c
===================================================================
--- roard/driver_dmx.c	(revision 5708)
+++ roard/driver_dmx.c	(revision 5754)
@@ -32,4 +32,5 @@
  struct roar_vio_calls * vio;
  int err;
+ const char * dev = device;
 
  if ( roar_vio_dstr_init_defaults(&def, ROAR_VIO_DEF_TYPE_NONE, O_WRONLY, 0644) == -1 )
@@ -42,11 +43,11 @@
 
  if ( fh == -1 ) {
-  if ( device == NULL )
-   device = getenv("DMX");
+  if ( dev == NULL )
+   dev = roar_env_get("DMX");
 
-  if ( device == NULL )
-   device = "/dev/dmx";
+  if ( dev == NULL )
+   dev = "/dev/dmx";
 
-  if ( roar_vio_open_dstr(vio, device, &def, 1) == -1 ) {
+  if ( roar_vio_open_dstr(vio, dev, &def, 1) == -1 ) {
    err = roar_error;
    roar_mm_free(vio);
Index: roard/include/roard.h
===================================================================
--- roard/include/roard.h	(revision 5740)
+++ roard/include/roard.h	(revision 5754)
@@ -162,6 +162,6 @@
 
 #ifdef ROAR_SUPPORT_LISTEN
-int get_listen(struct roard_listen ** sock, char *** sockname);
-int add_listen (char * addr, int port, int sock_type, char * user, char * group, int proto, int dir, struct roar_audio_info * info);
+int get_listen(struct roard_listen ** sock, const char *** sockname);
+int add_listen (const char * addr, int port, int sock_type, char * user, char * group, int proto, int dir, struct roar_audio_info * info);
 #endif
 
Index: roard/roard.c
===================================================================
--- roard/roard.c	(revision 5662)
+++ roard/roard.c	(revision 5754)
@@ -88,5 +88,5 @@
 
 #ifdef ROAR_SUPPORT_LISTEN
-static char * server[ROAR_MAX_LISTEN_SOCKETS];
+static const char * server[ROAR_MAX_LISTEN_SOCKETS];
 #endif
 
@@ -561,5 +561,5 @@
 }
 
-int get_listen(struct roard_listen ** sock, char *** sockname) {
+int get_listen(struct roard_listen ** sock, const char *** sockname) {
  int i;
 
@@ -786,5 +786,5 @@
 
 int get_listen_profile (const char * name,
-                        int * port, char ** sockaddr, int * type,
+                        int * port, const char ** sockaddr, int * type,
                         int * proto,
                         int * dir, struct roar_audio_info * info) {
@@ -798,5 +798,6 @@
 
    if ( p->type == ROAR_SOCKET_TYPE_UNIX && p->sockaddr[0] != '+' ) {
-    roar_env_render_path_r(buf, sizeof(buf), p->sockaddr);
+    if ( roar_env_render_path_r(buf, sizeof(buf), p->sockaddr) == -1 )
+     continue;
    } else {
     strncpy(buf, p->sockaddr, sizeof(buf));
@@ -822,5 +823,5 @@
 #endif
 
-int add_listen (char * addr, int port, int sock_type, char * user, char * group, int proto, int dir, struct roar_audio_info * info) {
+int add_listen (const char * addr, int port, int sock_type, char * user, char * group, int proto, int dir, struct roar_audio_info * info) {
 #if defined(ROAR_HAVE_SETGID) && defined(ROAR_HAVE_IO_POSIX)
  struct group   * grp  = NULL;
@@ -861,5 +862,5 @@
 #ifdef ROAR_HAVE_UNIX
    if ( *addr == '/' ) {
-    if ( (env_roar_proxy_backup = getenv("ROAR_PROXY")) != NULL ) {
+    if ( (env_roar_proxy_backup = (char*)roar_env_get("ROAR_PROXY")) != NULL ) {
      env_roar_proxy_backup = roar_mm_strdup(env_roar_proxy_backup);
      unsetenv("ROAR_PROXY");
@@ -1214,5 +1215,5 @@
 // X11:
 #ifdef ROAR_HAVE_LIBX11
-int register_x11 (int unreg, char * sockname) {
+int register_x11 (int unreg, const char * sockname) {
  struct roar_x11_connection * x11con = NULL;
  int ret = 0;
@@ -1252,8 +1253,8 @@
 }
 
-int register_slp (int unreg, char * sockname) {
+int register_slp (int unreg, const char * sockname) {
 #ifdef ROAR_HAVE_LIBSLP
  static int regged = 0;
- static char * sn = NULL;
+ static const char * sn = NULL;
  SLPError err;
  SLPError callbackerr;
@@ -1437,5 +1438,5 @@
 #ifdef ROAR_SUPPORT_LISTEN
  int    port       = ROAR_DEFAULT_PORT;
- char * sock_addr  = NULL;
+ const char * sock_addr  = NULL;
  int    sock_proto = ROAR_PROTO_ROARAUDIO;
  int    sock_dir   = -1;
@@ -1449,6 +1450,6 @@
  int    s_prim    = 0;
 #endif
- char * o_drv     = getenv("ROAR_DRIVER");
- char * o_dev     = getenv("ROAR_DEVICE");
+ char * o_drv     = NULL;
+ char * o_dev     = NULL;
  char * o_opts    = NULL;
  int    o_prim    = 0;
@@ -1508,4 +1509,10 @@
  ROAR_DBG("main(*): starting roard...");
 
+// NOTE: those to lions can generate a memory leak. The OS will clean that up on exit.
+ if ( roar_env_get("ROAR_DRIVER") != NULL )
+  o_drv = roar_mm_strdup(roar_env_get("ROAR_DRIVER"));
+ if ( roar_env_get("ROAR_DEVICE") != NULL )
+  o_dev = roar_mm_strdup(roar_env_get("ROAR_DEVICE"));
+
  g_standby       =  0;
  g_autostandby   =  0;
@@ -1603,9 +1610,11 @@
 
 #ifdef ROAR_HAVE_GETUID
- if ( getuid() != 0 && getenv("HOME") != NULL ) {
+ if ( getuid() != 0 && roar_env_get("HOME") != NULL ) {
 /*
   snprintf(user_sock, 79, "%s/%s", (char*)getenv("HOME"), ROAR_DEFAULT_SOCK_USER);
 */
-  roar_env_render_path_r(user_sock, sizeof(user_sock), "~/" ROAR_DEFAULT_SOCK_USER);
+  if ( roar_env_render_path_r(user_sock, sizeof(user_sock), "~/" ROAR_DEFAULT_SOCK_USER) == -1 ) {
+   strncpy(user_sock, "/NX-SOCK", sizeof(user_sock));
+  }
   sock_addr = user_sock;
   ROAR_DBG("main(*): setting sock_addr='%s'", sock_addr);
@@ -1613,6 +1622,6 @@
 #endif
 
- if ( getenv("ROAR_SERVER") != NULL )
-  sock_addr = getenv("ROAR_SERVER");
+ if ( roar_env_get("ROAR_SERVER") != NULL )
+  sock_addr = roar_env_get("ROAR_SERVER");
 #endif
 
