[08/13] libfrog: fix missing error checking in bitmap code
diff mbox series

Message ID 156685494799.2841546.16122304263421924560.stgit@magnolia
State Superseded
Headers show
Series
  • libfrog/xfs_scrub: fix error handling
Related show

Commit Message

Darrick J. Wong Aug. 26, 2019, 9:29 p.m. UTC
From: Darrick J. Wong <darrick.wong@oracle.com>

Check library calls for error codes being returned.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 libfrog/bitmap.c |   20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

Patch
diff mbox series

diff --git a/libfrog/bitmap.c b/libfrog/bitmap.c
index be95965f..82ac8210 100644
--- a/libfrog/bitmap.c
+++ b/libfrog/bitmap.c
@@ -72,21 +72,30 @@  bitmap_alloc(
 	struct bitmap		**bmapp)
 {
 	struct bitmap		*bmap;
+	int			ret;
 
 	bmap = calloc(1, sizeof(struct bitmap));
 	if (!bmap)
 		return errno;
 	bmap->bt_tree = malloc(sizeof(struct avl64tree_desc));
 	if (!bmap->bt_tree) {
-		free(bmap);
-		return errno;
+		ret = errno;
+		goto out;
 	}
 
-	pthread_mutex_init(&bmap->bt_lock, NULL);
+	ret = pthread_mutex_init(&bmap->bt_lock, NULL);
+	if (ret)
+		goto out_tree;
+
 	avl64_init_tree(bmap->bt_tree, &bitmap_ops);
 	*bmapp = bmap;
 
 	return 0;
+out_tree:
+	free(bmap->bt_tree);
+out:
+	free(bmap);
+	return ret;
 }
 
 /* Free a bitmap. */
@@ -217,7 +226,10 @@  bitmap_set(
 {
 	int			res;
 
-	pthread_mutex_lock(&bmap->bt_lock);
+	res = pthread_mutex_lock(&bmap->bt_lock);
+	if (res)
+		return res;
+
 	res = __bitmap_set(bmap, start, length);
 	pthread_mutex_unlock(&bmap->bt_lock);