+ if (getsockname(fd, sockaddr, (socklen_t *)&alloc_size) < 0) {
+ PERROR("getsockname failed");
+ goto free_sockaddr;
+ }
+
+ /* Destroy socket */
+ result = stat(sockaddr->sun_path, &st);
+ if(result < 0) {
+ PERROR("stat (%s)", sockaddr->sun_path);
+ goto free_sockaddr;
+ }
+
+ /* Paranoid check before deleting. */
+ result = S_ISSOCK(st.st_mode);
+ if(!result) {
+ ERR("The socket we are about to delete is not a socket.");
+ goto free_sockaddr;
+ }
+
+ result = unlink(sockaddr->sun_path);
+ if(result < 0) {
+ PERROR("unlink");
+ }
+ }
+
+free_sockaddr:
+ free(sockaddr);
+
+del_sock:
+ ustcomm_del_sock(sock, keep_socket_file);