From nobody Fri Jan 13 21:24:46 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4NtvZR55D3z2qkqV; Fri, 13 Jan 2023 21:24:47 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4NtvZR3Fc1z40Vb; Fri, 13 Jan 2023 21:24:47 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1673645087; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=7SFgg/uWx2gKOA1KlqVBGBeO7xId1aeFNo5AVTQgXCQ=; b=CV51eKZYIUnlaH3wpGgryI/8gOuBbG8riwFj3sswo6pZYT2joxSQjP18No/kJnsDRe6Vsq vyEHiJjrwHh5b/k6dFFOadygKk+GwsAohrwfbenwB10M1ZeyoQmO9rrXAXsDCLRZHm+Kb+ k7h7u3zmom9EfZFGM6lKpwvrVHHz3GDgi0Pvw02WdWRMwfOggM9bjV6gSE83vkRj9bHElk uNTiuHljQTCZTIn2xPkrEMngDbXdHidKBU7IoEB38N0PAl89igU4mx8pf5BS9zTe8VRLCP CJHxs4R/dxWCPd26kQ6BpkgUqBs92YNXURdU26lpgWIaHamCr3Jm5dYlsakPdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1673645087; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=7SFgg/uWx2gKOA1KlqVBGBeO7xId1aeFNo5AVTQgXCQ=; b=bFf7mu6t7wZxPV4E9hY71CXondW65c+LgTsEaVS6FG5v1Ga3qaf+0YV10ywknfJD776f2a pkzwHwYjoh5z8Mt5j8WvpmJSNxGr0gUs2Xk9D2F/yDqdBmF8yUNuHqS9SaiEZ3jmW326fY t+pEYE+g/FHqcsFqukwkh5o+RanbNRsUbQYcpvQBKqJl7hHLneAqJJKctQCCVoX6JC/LbL w9afEdKja9rAeB0QtHeJd/QwStbEPm9Yvxrf98+jR9FoQRBhu7D+0oyKGIGmL86IhZepeo 4adyO9HbwV4w8tyPXFkhj6feLCql8ZXf8VBIl+sisd8Jy27iP1nRP3t5p7qt6w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1673645087; a=rsa-sha256; cv=none; b=LUTOm3WIXRBSP2u9crHKCJiW0MMw5ChwzUJB90gWTeDQCJ4gDKddP5DOWIHWOYV1oGJDH2 U9qXUE/sYJ+OWZYu7ymkdsXO/aw3XVLFp+mkggn2jsPl1Y2jJ5hFpvg1zlq1fmzuAAzFgW gXYZkVQeHUjq14kTX5Rwp1rviEIy0a43CPiiAKmmGFSRym+hREZQrISTL7WIqkOfz1xpN2 SXl5Wv7YpmqBPIDD3wOM2GaspHwiGyIKgjuIdinHwEgqY1ySFAiWi8kFaTJoPkm4a0XJPz WIieVgmos9YLgiVMcqVOI7lxl+AcovertBYOhjYwyss4GpWds5ubsoVEHn1JrA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4NtvZR0YfVzMv4; Fri, 13 Jan 2023 21:24:47 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 30DLOkxI040680; Fri, 13 Jan 2023 21:24:46 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 30DLOkTf040679; Fri, 13 Jan 2023 21:24:46 GMT (envelope-from git) Date: Fri, 13 Jan 2023 21:24:46 GMT Message-Id: <202301132124.30DLOkTf040679@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Warner Losh Subject: git: 5385c7e13b06 - main - stand/zfs: Fix memory leaking on error cases List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: imp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 5385c7e13b06cb42a28bbf8c0d910b0c2ffddec7 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=5385c7e13b06cb42a28bbf8c0d910b0c2ffddec7 commit 5385c7e13b06cb42a28bbf8c0d910b0c2ffddec7 Author: Warner Losh AuthorDate: 2023-01-13 21:20:00 +0000 Commit: Warner Losh CommitDate: 2023-01-13 21:22:38 +0000 stand/zfs: Fix memory leaking on error cases Now that we return an allocated zfs_devdesc, we have to free it. These frees were missing from the error cases. In addition, simplify the code a bit for the out of memory case. Sponsored by: Netflix Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D38006 --- stand/libsa/zfs/zfs.c | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/stand/libsa/zfs/zfs.c b/stand/libsa/zfs/zfs.c index 57fecf2f4d68..3d5a392dd03f 100644 --- a/stand/libsa/zfs/zfs.c +++ b/stand/libsa/zfs/zfs.c @@ -379,9 +379,9 @@ zfs_readdir(struct open_file *f, struct dirent *d) static int zfs_mount(const char *dev, const char *path, void **data) { - struct zfs_devdesc *zfsdev; + struct zfs_devdesc *zfsdev = NULL; spa_t *spa; - struct zfsmount *mnt; + struct zfsmount *mnt = NULL; int rv; errno = 0; @@ -391,36 +391,46 @@ zfs_mount(const char *dev, const char *path, void **data) } spa = spa_find_by_dev(zfsdev); - if (spa == NULL) - return (ENXIO); + if (spa == NULL) { + rv = ENXIO; + goto err; + } mnt = calloc(1, sizeof(*mnt)); - if (mnt != NULL && path != NULL) + if (mnt == NULL) { + rv = ENOMEM; + goto err; + } + + if (mnt->path != NULL) { mnt->path = strdup(path); - rv = errno; + if (mnt->path == NULL) { + rv = ENOMEM; + goto err; + } + } - if (mnt != NULL) - rv = zfs_mount_impl(spa, zfsdev->root_guid, mnt); - free(zfsdev); + rv = zfs_mount_impl(spa, zfsdev->root_guid, mnt); - if (rv == 0 && mnt != NULL && mnt->objset.os_type != DMU_OST_ZFS) { + if (rv == 0 && mnt->objset.os_type != DMU_OST_ZFS) { printf("Unexpected object set type %ju\n", (uintmax_t)mnt->objset.os_type); rv = EIO; } - +err: if (rv != 0) { if (mnt != NULL) free(mnt->path); free(mnt); + free(zfsdev); return (rv); } - if (mnt != NULL) { - *data = mnt; - if (path != NULL) - STAILQ_INSERT_TAIL(&zfsmount, mnt, next); - } + *data = mnt; + if (path != NULL) + STAILQ_INSERT_TAIL(&zfsmount, mnt, next); + + free(zfsdev); return (rv); }