minor patch for kernel/sysctl.c

Bill Hawes (whawes@star.net)
Sat, 10 Jan 1998 18:03:25 -0500


This is a multi-part message in MIME format.
--------------63390CD4C2721F10352FFCF9
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

There seems to be a small memory leak in sysctl.c -- after allocating a
ctl_table_header to install a table, it doesn't get released when the
table in unlinked. It's a small structure, but conceivably a module
loaded and unloaded frequently could make a significant leak.

The attached patch adds a kfree() after unlinking the header, and also
clears out the table->de pointer in the ctl_table structures. I'd prefer
to avoid having stale pointers in the tables after the proc_dir_entries
are released.

Regards,
Bill
--------------63390CD4C2721F10352FFCF9
Content-Type: text/plain; charset=us-ascii; name="sysctl_78-patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="sysctl_78-patch"

--- kernel/sysctl.c.old Mon Dec 22 10:45:45 1997
+++ kernel/sysctl.c Sat Jan 10 16:51:19 1998
@@ -435,12 +435,16 @@
return tmp;
}

-void unregister_sysctl_table(struct ctl_table_header * table)
+/*
+ * Unlink and free a ctl_table.
+ */
+void unregister_sysctl_table(struct ctl_table_header * header)
{
- DLIST_DELETE(table, ctl_entry);
+ DLIST_DELETE(header, ctl_entry);
#ifdef CONFIG_PROC_FS
- unregister_proc_table(table->ctl_table, &proc_sys_root);
+ unregister_proc_table(header->ctl_table, &proc_sys_root);
#endif
+ kfree(header);
}

/*
@@ -457,18 +461,20 @@
mode_t mode;

for (; table->ctl_name; table++) {
- de = 0;
/* Can't do anything without a proc name. */
if (!table->procname)
continue;
/* Maybe we can't do anything with it... */
- if (!table->proc_handler &&
- !table->child)
+ if (!table->proc_handler && !table->child) {
+ printk(KERN_WARNING "SYSCTL: Can't register %s\n",
+ table->procname);
continue;
+ }

len = strlen(table->procname);
mode = table->mode;

+ de = NULL;
if (table->proc_handler)
mode |= S_IFREG;
else {
@@ -495,6 +501,9 @@
}
}

+/*
+ * Unregister a /proc sysctl table and any subdirectories.
+ */
static void unregister_proc_table(ctl_table * table, struct proc_dir_entry *root)
{
struct proc_dir_entry *de;
@@ -512,8 +521,11 @@
entries... */
if (!((de->mode & S_IFDIR) && de->subdir)) {
proc_unregister(root, de->low_ino);
+ table->de = NULL;
kfree(de);
- }
+ } else
+ printk("unregister_proc_table: %s not empty!\n",
+ table->procname);
}
}

--------------63390CD4C2721F10352FFCF9--