Skip to contentSkip to conversation

quotaio_xfs: Fix memory leak

PATCH In review Pavel Reichl 2 participants 2 messages Jul 29, 2024 – Jul 30, 2024 VFS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 quotaio_xfs: Fix memory leak

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.

---
 quotaio_xfs.c | 1 +
 1 file changed, 1 insertion(+)
quotaio_xfs.c +1 -0
index 2df27b5..5446bc5 100644
@@ -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;
 		}
 	}
Signature · 1 line
2.45.2
reviewer
#1 lore raw
Quoted 6 lines · Pavel Reichl

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.

Thanks for the fix! Applied.

Honza

Quoted 19 lines
---
 quotaio_xfs.c | 1 +
 1 file changed, 1 insertion(+)
quotaio_xfs.c +1 -0
index 2df27b5..5446bc5 100644
@@ -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;
 		}
 	}
Signature · 1 line
2.45.2
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR