From 83c2fa73e682235d96a356991ed9028d782c5796 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Date: Mon, 30 Jul 2018 11:27:51 +0000 Subject: xen-blkfront: fix memory leak in xbd_connect error path If gnttab_grant_foreign_access() fails for any of the indirection pages, the code breaks out of both the loops without freeing the local variable indirectpages, causing a memory leak. Submitted by: Pratyush Yadav Differential Review: https://reviews.freebsd.org/D16136 --- sys/dev/xen/blkfront/blkfront.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'sys/dev/xen') diff --git a/sys/dev/xen/blkfront/blkfront.c b/sys/dev/xen/blkfront/blkfront.c index 1f21fb838e9d..26f935199b99 100644 --- a/sys/dev/xen/blkfront/blkfront.c +++ b/sys/dev/xen/blkfront/blkfront.c @@ -1333,7 +1333,10 @@ xbd_connect(struct xbd_softc *sc) if (sc->xbd_max_request_indirectpages > 0) { indirectpages = contigmalloc( PAGE_SIZE * sc->xbd_max_request_indirectpages, - M_XENBLOCKFRONT, M_ZERO, 0, ~0, PAGE_SIZE, 0); + M_XENBLOCKFRONT, M_ZERO | M_NOWAIT, 0, ~0, + PAGE_SIZE, 0); + if (indirectpages == NULL) + sc->xbd_max_request_indirectpages = 0; } else { indirectpages = NULL; } @@ -1345,8 +1348,12 @@ xbd_connect(struct xbd_softc *sc) &cm->cm_indirectionrefs[j])) break; } - if (j < sc->xbd_max_request_indirectpages) + if (j < sc->xbd_max_request_indirectpages) { + contigfree(indirectpages, + PAGE_SIZE * sc->xbd_max_request_indirectpages, + M_XENBLOCKFRONT); break; + } cm->cm_indirectionpages = indirectpages; xbd_free_command(cm); } -- cgit v1.2.3