From nobody Tue Jan 24 22:14:27 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 4P1h8g6cpfz3bgm0; Tue, 24 Jan 2023 22:14:27 +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 4P1h8g38Tjz3Lbg; Tue, 24 Jan 2023 22:14:27 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674598467; 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=JypMySRbeiZr9x5YazEu8wAz0Y7xubzr60GyIGBCtDM=; b=XXpyhd2+h43Ih/j9WsUKVxbxs0tEZJyhSQ1BBw8VYBQwanN+EcirUvmdISLhqssBEnASLq SCuZaiMKJ48O9342yC1hkMj7+VbmbR/BLWCW7bhn79Ya/dM0bbUhIB4AXxJV4ifP190STA fgOab+d00agV0+rKTA5fRGwZJi7USJiY1uWeSLf48KxGWSe+oS9xiKls6bJnWgrN97L75l 3bewrfjrbh6FfvVmIhkILDA95HlFLa47557+U/xIyicokIri0rOSff9PQDX/3b7o0tsw3Y +ar4Fj1vU0tSPuNqJUIDoxnOCjji8L3+f5zyMshCKyWDnV7Q5ke0HzGkWZJKHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674598467; 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=JypMySRbeiZr9x5YazEu8wAz0Y7xubzr60GyIGBCtDM=; b=MOT+cdKLcuYoqeOVfnbFgKi39KGASTlWB4L3bBSBfxLU0pZK/YXfAVYa6BSt149FG7AFBq ueyBiVReaTyiniRwWQ+P4d1XbLd4/sG0oq8sW7V3YkjewZRfL/H1HbY12bSM1h7wRqUvFJ FW715Fl+HrMAf3H97eOPDkAeUpbYbyBc0FacQeWKCK06KlPB1bNd9f+PxdKMc9OBvJWVAL OyCyeviZR1JQQbGpcKT5xILdO/N+69atwVlaLqDE5Sdr7jlciMHKSEIVQ1qetetuypAXSL bip0ka/QxoID0xjA00IKGNySF4EMUNQT268RiXdDpgurRzi9VRlZ9nV2CUGeNw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1674598467; a=rsa-sha256; cv=none; b=WeATM81gkZ1Arv9ne10ORZZFrAa38rj1mgM+xlS4bAY1rHhwFL/Ts+1jt4XRdULzwnpClH 2fZCDg4YEXFvO9evxjOXB/g6i8JaYTIs9WiWkSoIeYQFHmrn4JZyoDFcRstzptSRurFDVk 9rMPc5ySNv8Hls9KRVboNcgZxbYLYVbv1lkZAxy2yM7i3C+QntCVhyDPd/s+YieQemyTDR zLe6omW8lk2flMjxDFyHrgL9unprIqLwl9c6i/WZNYrJbqzpvd4XEVhu1h8Xm+5YkcS8PF qehz1dRxrK7w+9GPGuhIhlVTJrZGT0+vvAR+jEyBggb2iVPLBJfdOD+BbmzHFQ== 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 4P1h8g2G0xzQsB; Tue, 24 Jan 2023 22:14:27 +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 30OMERcR089839; Tue, 24 Jan 2023 22:14:27 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 30OMEREf089838; Tue, 24 Jan 2023 22:14:27 GMT (envelope-from git) Date: Tue, 24 Jan 2023 22:14:27 GMT Message-Id: <202301242214.30OMEREf089838@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Warner Losh Subject: git: 379f5668e24a - stable/13 - 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/stable/13 X-Git-Reftype: branch X-Git-Commit: 379f5668e24ac173d7ab4cd865e82bccef6b1540 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=379f5668e24ac173d7ab4cd865e82bccef6b1540 commit 379f5668e24ac173d7ab4cd865e82bccef6b1540 Author: Warner Losh AuthorDate: 2023-01-13 21:20:00 +0000 Commit: Warner Losh CommitDate: 2023-01-24 21:49:46 +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 (cherry picked from commit 5385c7e13b06cb42a28bbf8c0d910b0c2ffddec7) --- 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); }