--- dillo-3.3.0.orig/src/dilloc.c
+++ dillo-3.3.0/src/dilloc.c
@@ -16,6 +16,7 @@
 #include <dirent.h>
 #include <errno.h>
 #include <limits.h>
+#define _GNU_SOURCE
 #include <stdio.h>
 #include <stdlib.h>
 #include <sys/ioctl.h>
@@ -104,9 +105,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,10 +117,11 @@ 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;
    }
 
-   int found_pid = 0;
+	   int found_pid = 0;
    struct sockaddr_un addr;
    addr.sun_family = AF_UNIX;
 
@@ -136,6 +138,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 +146,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 +174,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;
