Skip to content

Commit

Permalink
pam: free the CString allocated for pam_putenv
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Lytvynov authored and awly committed May 19, 2020
1 parent 8eb624a commit 9d33512
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/pam/pam.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,8 @@ func Open(config *Config) (*PAM, error) {
// Also set it via PAM-specific pam_putenv, which is respected by
// pam_exec (and possibly others), where parent env vars are not.
kv := C.CString(fmt.Sprintf("%s=%s", k, v))
// pam_putenv makes a copy of kv, so we can free it right away.
defer C.free(unsafe.Pointer(kv))
retval := C._pam_putenv(pamHandle, p.pamh, kv)
if retval != C.PAM_SUCCESS {
return nil, p.codeToError(retval)
Expand Down

0 comments on commit 9d33512

Please sign in to comment.