diff mbox series

quotaio_xfs: Fix memory leak

Message ID 20240729221813.93878-1-preichl@redhat.com (mailing list archive)
State New
Headers show
Series quotaio_xfs: Fix memory leak | expand

Commit Message

Pavel Reichl July 29, 2024, 10:18 p.m. UTC
Error: RESOURCE_LEAK (CWE-772):
quota-4.09/quotaio_xfs.c:162:2: alloc_fn: Storage is returned from allocation function "get_empty_dquot".
quota-4.09/quotaio_xfs.c:162:2: var_assign: Assigning: "dquot" = storage returned from "get_empty_dquot()".
quota-4.09/quotaio_xfs.c:180:4: leaked_storage: Variable "dquot" going out of scope leaks the storage it points to.

Signed-off-by: Pavel Reichl <preichl@redhat.com>
---
 quotaio_xfs.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Jan Kara July 30, 2024, 12:50 p.m. UTC | #1
On Tue 30-07-24 00:18:13, Pavel Reichl wrote:
> Error: RESOURCE_LEAK (CWE-772):
> quota-4.09/quotaio_xfs.c:162:2: alloc_fn: Storage is returned from allocation function "get_empty_dquot".
> quota-4.09/quotaio_xfs.c:162:2: var_assign: Assigning: "dquot" = storage returned from "get_empty_dquot()".
> quota-4.09/quotaio_xfs.c:180:4: leaked_storage: Variable "dquot" going out of scope leaks the storage it points to.
> 
> Signed-off-by: Pavel Reichl <preichl@redhat.com>

Thanks for the fix! Applied.

								Honza

> ---
>  quotaio_xfs.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/quotaio_xfs.c b/quotaio_xfs.c
> index 2df27b5..5446bc5 100644
> --- a/quotaio_xfs.c
> +++ b/quotaio_xfs.c
> @@ -174,6 +174,7 @@ static struct dquot *xfs_read_dquot(struct quota_handle *h, qid_t id)
>  		 * zeros. Otherwise return failure.
>  		 */
>  		if (errno != ENOENT) {
> +			free(dquot);
>  			return NULL;
>  		}
>  	}
> -- 
> 2.45.2
>
diff mbox series

Patch

diff --git a/quotaio_xfs.c b/quotaio_xfs.c
index 2df27b5..5446bc5 100644
--- a/quotaio_xfs.c
+++ b/quotaio_xfs.c
@@ -174,6 +174,7 @@  static struct dquot *xfs_read_dquot(struct quota_handle *h, qid_t id)
 		 * zeros. Otherwise return failure.
 		 */
 		if (errno != ENOENT) {
+			free(dquot);
 			return NULL;
 		}
 	}