From 02b31a0ee98e10caa96638dca832ac44ac51d67f Mon Sep 17 00:00:00 2001 From: Ian Dowse Date: Wed, 1 Aug 2001 10:25:13 +0000 Subject: [PATCH] Fix a client-side memory leak in nfs_flush(). The code allocates a temporary array to store struct buf pointers if the list doesn't fit in a local array. Usually it frees the array when finished, but if it jumps to the 'again' label and the new list does fit in the local array then it can forget to free a previously malloc'd M_TEMP memory. Move the free() up a line so that it frees any previously allocated memory whether or not it needs to malloc a new array. Reviewed by: dillon --- sys/nfs/nfs_vnops.c | 4 ++-- sys/nfsclient/nfs_vnops.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sys/nfs/nfs_vnops.c b/sys/nfs/nfs_vnops.c index d37615a47b0..5b84741de52 100644 --- a/sys/nfs/nfs_vnops.c +++ b/sys/nfs/nfs_vnops.c @@ -2802,9 +2802,9 @@ again: * If we can't get memory (for whatever reason), we will end up * committing the buffers one-by-one in the loop below. */ + if (bvec != NULL && bvec != bvec_on_stack) + free(bvec, M_TEMP); if (bveccount > NFS_COMMITBVECSIZ) { - if (bvec != NULL && bvec != bvec_on_stack) - free(bvec, M_TEMP); bvec = (struct buf **) malloc(bveccount * sizeof(struct buf *), M_TEMP, M_NOWAIT); diff --git a/sys/nfsclient/nfs_vnops.c b/sys/nfsclient/nfs_vnops.c index d37615a47b0..5b84741de52 100644 --- a/sys/nfsclient/nfs_vnops.c +++ b/sys/nfsclient/nfs_vnops.c @@ -2802,9 +2802,9 @@ again: * If we can't get memory (for whatever reason), we will end up * committing the buffers one-by-one in the loop below. */ + if (bvec != NULL && bvec != bvec_on_stack) + free(bvec, M_TEMP); if (bveccount > NFS_COMMITBVECSIZ) { - if (bvec != NULL && bvec != bvec_on_stack) - free(bvec, M_TEMP); bvec = (struct buf **) malloc(bveccount * sizeof(struct buf *), M_TEMP, M_NOWAIT);