diff options
author | kib <kib@FreeBSD.org> | 2007-12-29 14:28:01 +0000 |
---|---|---|
committer | kib <kib@FreeBSD.org> | 2007-12-29 14:28:01 +0000 |
commit | 66636dffb7d36cbf4589819a1314728683df3120 (patch) | |
tree | 87d2f07bfe1e758c2af5ad90ea8ef1d4e065b555 /sys/compat/linux/linux_file.c | |
parent | 6dc4f55b5511f713d99d0c9ddf7bc0125318384a (diff) | |
download | FreeBSD-src-66636dffb7d36cbf4589819a1314728683df3120.zip FreeBSD-src-66636dffb7d36cbf4589819a1314728683df3120.tar.gz |
Plug the leaks in the present (hopefully, soon to be replaced)
implementation of the linux_openat() for the quick MFC.
Reported and tested by: Peter Holm
MFC after: 3 days
Diffstat (limited to 'sys/compat/linux/linux_file.c')
-rw-r--r-- | sys/compat/linux/linux_file.c | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/sys/compat/linux/linux_file.c b/sys/compat/linux/linux_file.c index bee733c..dc9fd19 100644 --- a/sys/compat/linux/linux_file.c +++ b/sys/compat/linux/linux_file.c @@ -251,34 +251,41 @@ linux_at(struct thread *td, int dirfd, char *filename, char **newpath, char **fr int linux_openat(struct thread *td, struct linux_openat_args *args) { - char *newpath, *oldpath, *freebuf = NULL, *path; + char *newpath, *oldpath, *freebuf, *path; int error; oldpath = malloc(MAXPATHLEN, M_TEMP, M_WAITOK); error = copyinstr(args->filename, oldpath, MAXPATHLEN, NULL); - + if (error) { + free(oldpath, M_TEMP); + return (error); + } #ifdef DEBUG if (ldebug(openat)) printf(ARGS(openat, "%i, %s, 0x%x, 0x%x"), args->dfd, oldpath, args->flags, args->mode); #endif - + newpath = freebuf = NULL; error = linux_at(td, args->dfd, oldpath, &newpath, &freebuf); - if (error) - return (error); + if (error == 0) { #ifdef DEBUG - printf(LMSG("newpath: %s"), newpath); + if (ldebug(openat)) + printf(LMSG("newpath: %s"), newpath); #endif - if (args->flags & LINUX_O_CREAT) - LCONVPATH_SEG(td, newpath, &path, 1, UIO_SYSSPACE); - else - LCONVPATH_SEG(td, newpath, &path, 0, UIO_SYSSPACE); + if (args->flags & LINUX_O_CREAT) + LCONVPATH_SEG(td, newpath, &path, 1, UIO_SYSSPACE); + else + LCONVPATH_SEG(td, newpath, &path, 0, UIO_SYSSPACE); + } if (freebuf) free(freebuf, M_TEMP); if (*oldpath != '/') free(newpath, M_TEMP); - - error = linux_common_open(td, path, args->flags, args->mode, 1); + if (error == 0) { + error = linux_common_open(td, path, args->flags, + args->mode, 1); + LFREEPATH(path); + } free(oldpath, M_TEMP); return (error); } |