Bug 269509 - Memory leak in ofwbus
Summary: Memory leak in ofwbus
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Many People
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-02-12 07:47 UTC by Jaroslaw Pelczar
Modified: 2023-04-17 14:08 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jaroslaw Pelczar 2023-02-12 07:47:39 UTC
The ofwbus_attach function (in sys/dev/ofw/ofwbus.c) performs iteration over nodes.

	for (node = OF_child(node); node > 0; node = OF_peer(node)) {
		if (ofw_bus_gen_setup_devinfo(&obd, node) != 0)
			continue;
		simplebus_add_device(dev, node, 0, NULL, -1, NULL);
	}

ofw_bus_gen_setup_devinfo allocates memory to temporary buffer, however this memory is never freed, so the change should probably look as follows:

	for (node = OF_child(node); node > 0; node = OF_peer(node)) {
		if (ofw_bus_gen_setup_devinfo(&obd, node) != 0)
		 	continue;
		simplebus_add_device(dev, node, 0, NULL, -1, NULL);
+               ofw_bus_gen_destroy_devinfo(&obd);
	}
Comment 1 Christos Margiolis freebsd_committer freebsd_triage 2023-03-04 02:01:20 UTC
Opened a PR:
https://reviews.freebsd.org/D38903
Comment 2 commit-hook freebsd_committer freebsd_triage 2023-04-10 16:14:59 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=38594ff9c0c9568b5082ba3273103904a6afd38e

commit 38594ff9c0c9568b5082ba3273103904a6afd38e
Author:     Christos Margiolis <christos@FreeBSD.org>
AuthorDate: 2023-04-10 15:31:46 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2023-04-10 16:14:12 +0000

    ofw: fix memory leak in ofwbus_attach()

    PR:             269509
    Reported by:    Jaroslaw Pelczar <jarek@jpelczar.com>
    Reviewed by:    markj
    MFC after:      1 week
    Differential Revision:  https://reviews.freebsd.org/D38903

 sys/dev/ofw/ofwbus.c | 1 +
 1 file changed, 1 insertion(+)
Comment 3 commit-hook freebsd_committer freebsd_triage 2023-04-17 13:38:46 UTC
A commit in branch stable/13 references this bug:

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

commit da048bd318b3d144de0d4ad9596963d978a75e0f
Author:     Christos Margiolis <christos@FreeBSD.org>
AuthorDate: 2023-04-10 15:31:46 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2023-04-17 13:34:02 +0000

    ofw: fix memory leak in ofwbus_attach()

    PR:             269509
    Reported by:    Jaroslaw Pelczar <jarek@jpelczar.com>
    Reviewed by:    markj
    MFC after:      1 week
    Differential Revision:  https://reviews.freebsd.org/D38903

    (cherry picked from commit 38594ff9c0c9568b5082ba3273103904a6afd38e)

 sys/dev/ofw/ofwbus.c | 1 +
 1 file changed, 1 insertion(+)
Comment 4 Mark Johnston freebsd_committer freebsd_triage 2023-04-17 14:08:28 UTC
Thank you for the report.