linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] quotaio_xfs: Fix memory leak
@ 2024-07-29 22:18 Pavel Reichl
  2024-07-30 12:50 ` Jan Kara
  0 siblings, 1 reply; 2+ messages in thread
From: Pavel Reichl @ 2024-07-29 22:18 UTC (permalink / raw)
  To: jack; +Cc: linux-fsdevel

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(+)

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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] quotaio_xfs: Fix memory leak
  2024-07-29 22:18 [PATCH] quotaio_xfs: Fix memory leak Pavel Reichl
@ 2024-07-30 12:50 ` Jan Kara
  0 siblings, 0 replies; 2+ messages in thread
From: Jan Kara @ 2024-07-30 12:50 UTC (permalink / raw)
  To: Pavel Reichl; +Cc: jack, linux-fsdevel

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
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-07-30 12:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-29 22:18 [PATCH] quotaio_xfs: Fix memory leak Pavel Reichl
2024-07-30 12:50 ` Jan Kara

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).