From owner-dev-commits-src-branches@freebsd.org Sat Mar 6 19:38:47 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 4100C5711A1; Sat, 6 Mar 2021 19:38: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 4DtFK22RYvz4lM0; Sat, 6 Mar 2021 19:38:46 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 1714CE9B; Sat, 6 Mar 2021 19:38:45 +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 126Jci4Y007154; Sat, 6 Mar 2021 19:38:44 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 126JcimQ007153; Sat, 6 Mar 2021 19:38:44 GMT (envelope-from git) Date: Sat, 6 Mar 2021 19:38:44 GMT Message-Id: <202103061938.126JcimQ007153@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Jung-uk Kim Subject: git: 24ee1eb2b680 - stable/12 - libkvm: Plug couple of memory leaks and check possible calloc(3) failure MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jkim X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: 24ee1eb2b680b5ee1e6943f6dbc76d98a640d9d8 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 06 Mar 2021 19:38:47 -0000 The branch stable/12 has been updated by jkim: URL: https://cgit.FreeBSD.org/src/commit/?id=24ee1eb2b680b5ee1e6943f6dbc76d98a640d9d8 commit 24ee1eb2b680b5ee1e6943f6dbc76d98a640d9d8 Author: Jung-uk Kim AuthorDate: 2021-03-03 23:10:00 +0000 Commit: Jung-uk Kim CommitDate: 2021-03-06 19:35:10 +0000 libkvm: Plug couple of memory leaks and check possible calloc(3) failure First, r204494 introduced dpcpu_off in struct __kvm and it was allocated from _kvm_dpcpu_init() but it was not free(3)'ed from kvm_close(3). Second, r291406 introduced kvm_nlist2(3) and converted kvm_nlist(3) to use the new function but it did not free the temporary buffer. Also, check possible calloc(3) failure while I am in the neighborhood. Differential Revision: https://reviews.freebsd.org/D29019 (cherry picked from commit 645eaa2ccaed6eea801d07d6a092974fc1713896) (cherry picked from commit 483c6da3a20b2064cd655f7cb19e6b98dee677ff) --- lib/libkvm/kvm.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/libkvm/kvm.c b/lib/libkvm/kvm.c index 2f35f26df1ca..2a148399a211 100644 --- a/lib/libkvm/kvm.c +++ b/lib/libkvm/kvm.c @@ -295,6 +295,8 @@ kvm_close(kvm_t *kd) free((void *) kd->argspc); if (kd->argv != 0) free((void *)kd->argv); + if (kd->dpcpu_initialized != 0) + free(kd->dpcpu_off); if (kd->pt_map != NULL) free(kd->pt_map); if (kd->page_map != NULL) @@ -338,6 +340,10 @@ kvm_nlist(kvm_t *kd, struct nlist *nl) if (count == 0) return (0); kl = calloc(count + 1, sizeof(*kl)); + if (kl == NULL) { + _kvm_err(kd, kd->program, "cannot allocate memory"); + return (-1); + } for (i = 0; i < count; i++) kl[i].n_name = nl[i].n_name; nfail = kvm_nlist2(kd, kl); @@ -347,6 +353,7 @@ kvm_nlist(kvm_t *kd, struct nlist *nl) nl[i].n_desc = 0; nl[i].n_value = kl[i].n_value; } + free(kl); return (nfail); }