git: 28ddd11d91f8 - main - bsnmpd/snmp_hostres: fix hrFSTable remoteMountPoint leak

From: Mariusz Zaborski <oshogbo_at_FreeBSD.org>
Date: Fri, 19 Jun 2026 12:03:40 UTC
The branch main has been updated by oshogbo:

URL: https://cgit.FreeBSD.org/src/commit/?id=28ddd11d91f860df9b9be485c5b0526c10b4aec1

commit 28ddd11d91f860df9b9be485c5b0526c10b4aec1
Author:     Mariusz Zaborski <oshogbo@FreeBSD.org>
AuthorDate: 2026-06-19 11:58:17 +0000
Commit:     Mariusz Zaborski <oshogbo@FreeBSD.org>
CommitDate: 2026-06-19 11:58:17 +0000

    bsnmpd/snmp_hostres: fix hrFSTable remoteMountPoint leak
    
    Free the previous value before re-strdup'ing, and initialise
    remoteMountPoint to NULL in fs_entry_create() so the free() is safe on
    the newly-created path
    
    Observed via a dtrace leak snapshot on 15.0-RELEASE-p4:
      data leaked = 1983, count = 1683
        libc.so.7`malloc+0xa8
        snmp_hostres.so.6`fs_tbl_process_statfs_entry+0x276
        snmp_hostres.so.6`refresh_storage_tbl+0x502
        snmp_hostres.so.6`op_hrStorageTable+0x1a
        libbsnmp.so.7`0x2a2b1892ba3d
        libbsnmp.so.7`snmp_getbulk+0x37f
    
    Reviewed by:    sjg, ngie
    Differential Revision:  https://reviews.freebsd.org/D57604
---
 usr.sbin/bsnmpd/modules/snmp_hostres/hostres_fs_tbl.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_fs_tbl.c b/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_fs_tbl.c
index bdc20d19a372..147522036bf9 100644
--- a/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_fs_tbl.c
+++ b/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_fs_tbl.c
@@ -205,6 +205,7 @@ fs_entry_create(const char *name)
 		free(entry);
 		return (NULL);
 	}
+	entry->remoteMountPoint = NULL;
 
 	entry->index = map->hrIndex;
 	map->entry = entry;
@@ -352,6 +353,9 @@ fs_tbl_process_statfs_entry(const struct statfs *fs_p, int32_t storage_idx)
 	    (entry = fs_entry_create(fs_p->f_mntonname)) != NULL) {
 		entry->flags |= HR_FS_FOUND;
 
+		free(entry->remoteMountPoint);
+		entry->remoteMountPoint = NULL;
+
 		if (!(fs_p->f_flags & MNT_LOCAL)) {
 			/* this is a remote mount */
 			entry->remoteMountPoint = strdup(fs_p->f_mntfromname);