Skip to contentSkip to conversation

free of ap.path happens too early in cleanup

PATCH In review Jeff Moyer 2 participants 6 messages Mar 16, 2004 – Mar 18, 2004 Kernel automounter

lore
Share & tools
lore

Jeff Moyer

author
#0 lore raw

PATCH 1/1 free of ap.path happens too early in cleanup

Hello,

ap.path gets free-d before we are done with it. Specifically, callers of umount_autofs often-times reference ap.path when next calling cleanup_exit. This patch moves the free-ing of ap.path to cleanup_exit. Comments welcome.

-Jeff

daemon/automount.c renamed from daemon/automount.c.orig +2 -2
@@ -364,8 +364,6 @@ static int do_umount_autofs(void)
 			rm_unwanted(ap.path, 1, 1);
 	}
 
-	free(ap.path);
-
 	return rv;
 }
 
@@ -1327,6 +1325,8 @@ static void cleanup_exit(const char *pat
 		if (rmdir(path) == -1)
 			warn("failed to remove dir %s: %m", path);
 
+	free(ap.path);
+
 	exit(exit_code);
 }
maintainer
#1 lore raw
Quoted 7 lines · Jeff Moyer

Hello,

ap.path gets free-d before we are done with it. Specifically, callers of umount_autofs often-times reference ap.path when next calling cleanup_exit. This patch moves the free-ing of ap.path to cleanup_exit. Comments welcome.

Hi Jeff,

I don't mind moving the free as you recommend (it looks OK) but, after a quick look, I can't see where ap.path is referred to out of context?

Ian

author
#2 lore raw

==> Regarding Re: [autofs] [autofs-4.1.1 patch] free of ap.path happens too early in cleanup; Ian Kent <[email protected]> adds:

Quoted 7 lines · Jeff Moyer
Quoted 7 lines

Hello,

ap.path gets free-d before we are done with it. Specifically, callers of umount_autofs often-times reference ap.path when next calling cleanup_exit. This patch moves the free-ing of ap.path to cleanup_exit. Comments welcome.

raven> Hi Jeff,

raven> I don't mind moving the free as you recommend (it looks OK) but, raven> after a quick look, I can't see where ap.path is referred to out of raven> context?

Sorry, I should have included more information.

Check for calls to umount_autofs(1), such as the call in handle_mounts:

	if (map & LKP_FAIL) {
		if (map & LKP_INDIRECT)
			syslog(LOG_INFO,
			       "bad map format: found indirect, expected direct exiting");
		else
			syslog(LOG_INFO, "failed to load map, exiting");
		rm_unwanted(ap.path, 1, 1);
		umount_autofs(1);
		cleanup_exit(ap.path, 1);

In umount_autofs, we have this:

	if (umount_all(force) && !force)
		return -1;

	return do_umount_autofs();

If we follow through to do_umount_autofs, at the bottom we have this:

	free(ap.path);

	return rv;

Now, we will return to the top of our call stack, and call cleanup_exit(ap.path, 1);

This is just one example, there are a couple of others, I believe. It's really just a problem in error cases, but seems a good idea to fix.

Thanks!

Jeff

maintainer
#3 lore raw
Quoted 21 lines · Jeff Moyer

==> Regarding Re: [autofs] [autofs-4.1.1 patch] free of ap.path happens too early in cleanup; Ian Kent <[email protected]> adds:

Quoted 7 lines · Jeff Moyer
Quoted 7 lines

Hello,

ap.path gets free-d before we are done with it. Specifically, callers of umount_autofs often-times reference ap.path when next calling cleanup_exit. This patch moves the free-ing of ap.path to cleanup_exit. Comments welcome.

raven> Hi Jeff,

raven> I don't mind moving the free as you recommend (it looks OK) but, raven> after a quick look, I can't see where ap.path is referred to out of raven> context?

Sorry, I should have included more information.

Check for calls to umount_autofs(1), such as the call in handle_mounts:

Quoted 9 lines
	if (map & LKP_FAIL) {
		if (map & LKP_INDIRECT)
			syslog(LOG_INFO,
			       "bad map format: found indirect, expected direct exiting");
		else
			syslog(LOG_INFO, "failed to load map, exiting");
		rm_unwanted(ap.path, 1, 1);
		umount_autofs(1);
		cleanup_exit(ap.path, 1);

Ha! Developer blindness.

Maybe you could look a bit closer and a bit further, yes.

Ian

author
#4 lore raw

==> Regarding Re: [autofs] [autofs-4.1.1 patch] free of ap.path happens too early in cleanup; Ian Kent <[email protected]> adds:

[snip]
raven> Hi Jeff,

Quoted 1 line
Quoted 1 line

raven> I don't mind moving the free as you recommend (it looks OK) but, raven> after a quick look, I can't see where ap.path is referred to out of raven> context?

Quoted 8 lines
Quoted 8 lines

Sorry, I should have included more information.

Check for calls to umount_autofs(1), such as the call in handle_mounts:

if (map & LKP_FAIL) { if (map & LKP_INDIRECT) syslog(LOG_INFO, "bad map
format: found indirect, expected direct exiting"); else syslog(LOG_INFO, "failed to load map, exiting"); rm_unwanted(ap.path, 1, 1); umount_autofs(1); cleanup_exit(ap.path, 1);

raven> Ha! Developer blindness.

raven> Maybe you could look a bit closer and a bit further, yes.

Ugh. Turns out I was actually looking at the 4.1.0 sources. Terribly sorry.

-Jeff

[from the 4.1.0 - 4.1.1 diff]

- cleanup_exit(ap.path, 1);
+ cleanup_exit(path, 1);

maintainer
#5 lore raw

Review

Quoted 11 lines · Jeff Moyer

Ugh. Turns out I was actually looking at the 4.1.0 sources. Terribly sorry.

-Jeff

[from the 4.1.0 - 4.1.1 diff]

(quoted diff) +1 -1
-                               cleanup_exit(ap.path, 1);
+                               cleanup_exit(path, 1);

Oh yes. That was in the changelog.

I found it printing garbage on error exit.
There's probably no point in changing then.

Ian