sb-bsd-sockets: GET-ADDRESS-INFO foreign memory leak
[sbcl.git] / contrib / sb-bsd-sockets / name-service.lisp
index 3378ffa..8e96c7b 100644 (file)
@@ -20,7 +20,7 @@
   (car (host-ent-addresses host-ent)))
 
 (defun make-host-ent (h &optional errno)
-  (when (sb-grovel::foreign-nullp h)
+  (when (sb-alien:null-alien h)
     (name-service-error "gethostbyname" errno))
   (let* ((length (sockint::hostent-length h))
          (aliases (loop for i = 0 then (1+ i)
@@ -90,9 +90,9 @@ weird stuff - see gethostbyname(3) or getaddrinfo(3) for the details."
 
 #+sb-bsd-sockets-addrinfo
 (defun get-address-info (node)
-  (sb-alien:with-alien ((res (* (* sockint::addrinfo)) :local
-                             (sb-alien:make-alien (* sockint::addrinfo))))
-    (let ((err (sockint::getaddrinfo node nil nil res)))
+  (sb-alien:with-alien ((buf (sb-alien:array (* sockint::addrinfo) 1)))
+    (let* ((res (sb-alien:addr (sb-alien:deref buf 0)))
+           (err (sockint::getaddrinfo node nil nil res)))
       (if (zerop err)
           (let ((host-ent (make-instance 'host-ent
                                          :name node
@@ -114,7 +114,7 @@ weird stuff - see gethostbyname(3) or getaddrinfo(3) for the details."
                                                                          4)
                                        (host-ent-addresses host-ent)
                                        :test 'equalp)))))
-            (sockint::free-addrinfo (sb-alien:deref res))
+            (sockint::freeaddrinfo (sb-alien:deref res))
             host-ent)
           (addrinfo-error "getaddrinfo" err)))))
 
@@ -170,7 +170,7 @@ GET-NAME-SERVICE-ERRNO")
   (let ((condition (condition-for-name-service-error-code error-code)))
     (error condition :error-code error-code :syscall where)))
 
-(define-condition name-service-error (condition)
+(define-condition name-service-error (error)
   ((errno :initform nil :initarg :errno :reader name-service-error-errno)
    (error-code :initform nil :initarg :error-code
                :reader name-service-error-error-code)
@@ -230,8 +230,11 @@ GET-NAME-SERVICE-ERRNO")
     sockint::EAI-FAIL
     no-recovery-error)
 (define-name-service-condition
-    sockint::NO-ADDRESS  ;; Also defined as NO-DATA, with the same value
-    #-freebsd sockint::EAI-NODATA #+freebsd nil
+    ;; Also defined as NO-DATA, with the same value
+    sockint::NO-ADDRESS
+    ;; getaddrinfo() as of RFC 3493 can no longer distinguish between
+    ;; host no found and address not found
+    nil
     no-address-error)
 
 (defun condition-for-name-service-errno (err)