Raymond Toy pushed to branch issue-269-unix-get-user-homedir at cmucl / cmucl
Commits: a24b478f by Raymond Toy at 2023-11-29T16:15:10-08:00 Rewrite because os_get_user_homedir returns a new string
os_get_user_homedir returns a newly-allocated string as the result. The interface needs to free this space, so rewrite the caller appropiately so that we can free the space.
- - - - -
1 changed file:
- src/code/os.lisp
Changes:
===================================== src/code/os.lisp ===================================== @@ -67,18 +67,23 @@ if no errors occurred. Otherwise a non-zero value is returned. Examining errno may give information about what failed." (alien:with-alien ((status c-call:int)) - (let ((result - (alien:alien-funcall - (alien:extern-alien "os_get_user_homedir" - (function c-call:c-string - c-call:c-string - (* c-call:int))) - name - (alien:addr status)))) - (if (and (zerop status) result) - (values (pathname - (concatenate 'string - result - "/")) - status) - (values result status))))) + (let (result) + (unwind-protect + (progn + (setf result + (alien:alien-funcall + (alien:extern-alien "os_get_user_homedir" + (function (alien:* c-call:c-string) + c-call:c-string + (* c-call:int))) + name + (alien:addr status))) + (if (and (zerop status) + (not (alien:null-alien result))) + (values (pathname + (concatenate 'string + (alien:cast result c-call:c-string) + "/")) + status) + (values nil status))) + (alien:free-alien result)))))
View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/commit/a24b478ffed5ec6585bc6b42...