--- dillo-3.3.0.orig/src/dilloc.c
+++ dillo-3.3.0/src/dilloc.c
@@ -9,6 +9,8 @@
  * (at your option) any later version.
  */
 
+#define _GNU_SOURCE
+
 #include "config.h"
 
 #include "dlib/dlib.h" /* dIsdigit */
@@ -104,9 +106,9 @@ connect_given_pid(int *sock, const char
 static int
 find_working_socket(int *sock)
 {
-   char ctlpath[PATH_MAX];
-   if (snprintf(ctlpath, PATH_MAX, "%s/.dillo/ctl", dGethomedir()) >= PATH_MAX) {
-      fprintf(stderr, "path too long\n");
+   char *ctlpath = NULL;
+   if (asprintf(&ctlpath, "%s/.dillo/ctl", dGethomedir()) == -1) {
+      fprintf(stderr, "path copy error: %s\n",strerror(errno));
       return -1;
    }
 
@@ -116,6 +118,7 @@ find_working_socket(int *sock)
       fprintf(stderr, "error: cannot open %s directory: %s\n",
             ctlpath, strerror(errno));
       fprintf(stderr, "hint: is dillo running?\n");
+      free(ctlpath);
       return -1;
    }
 
@@ -136,6 +139,7 @@ find_working_socket(int *sock)
 #define LEN ((int) sizeof(addr.sun_path))
       if (snprintf(addr.sun_path, LEN, "%s/%s", ctlpath, num) >= LEN) {
          fprintf(stderr, "pid path too long\n");
+         free(ctlpath);
          return -1;
       }
 #undef LEN
@@ -143,6 +147,7 @@ find_working_socket(int *sock)
       int fd;
       if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
          fprintf(stderr, "socket() failed: %s\n", strerror(errno));
+         free(ctlpath);
          return -1;
       }
 
@@ -170,11 +175,13 @@ find_working_socket(int *sock)
 
       if (fd != -1 && dClose(fd) != 0) {
          fprintf(stderr, "cannot close fd: %s", strerror(errno));
+         free(ctlpath);
          return -1;
       }
    }
 
    closedir(dp);
+   free(ctlpath);
 
    if (found_pid == 1)
       return 0;
