From: Karel Zak Date: Wed, 12 Mar 2008 11:28:50 +0000 (+0100) Subject: mount: remove useless if-before-my_free, define my_free as a macro X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9a6cd8bdae7b1d24a7bf5ae03f4496cbd0d0671b;p=util-linux mount: remove useless if-before-my_free, define my_free as a macro Signed-off-by: Karel Zak --- diff --git a/mount/fstab.c b/mount/fstab.c index 277f4f1d..108010f9 100644 --- a/mount/fstab.c +++ b/mount/fstab.c @@ -99,12 +99,6 @@ fstab_head() { return &fstab; } -static void -my_free(const void *s) { - if (s) - free((void *) s); -} - static void my_free_mc(struct mntentchn *mc) { if (mc) { @@ -334,7 +328,7 @@ getfs_by_specdir (const char *spec, const char *dir) { if (streq(dr, dir)) ok = 1; - my_free(dr); + free(dr); if (!ok) continue; } @@ -354,7 +348,7 @@ getfs_by_specdir (const char *spec, const char *dir) { if (has_uuid(spec, fs + 5)) ok = 1; } - my_free(fs); + free(fs); if (!ok) continue; } @@ -404,7 +398,7 @@ getfs_by_spec (const char *spec) { else if (!strcmp(name,"UUID")) mc = getfs_by_uuid (value); - free((void *) name); + free(name); return mc; } diff --git a/mount/mount.c b/mount/mount.c index ccdcba53..5f66cb26 100644 --- a/mount/mount.c +++ b/mount/mount.c @@ -227,12 +227,6 @@ parse_string_opt(char *s) { return 0; } -static void -my_free(const void *s) { - if (s) - free((void *) s); -} - /* Report on a single mount. */ static void print_one (const struct my_mntent *me) { @@ -544,7 +538,7 @@ create_mtab (void) { mnt.mnt_type = fstab->m.mnt_type; mnt.mnt_opts = fix_opts_string (flags, extra_opts, NULL); mnt.mnt_freq = mnt.mnt_passno = 0; - my_free(extra_opts); + free(extra_opts); if (my_addmntent (mfp, &mnt) == 1) { int errsv = errno; @@ -1501,7 +1495,8 @@ mount_one (const char *spec, const char *node, const char *types, if (verbose && status2) printf (_("mount: giving up \"%s\"\n"), spec); - my_free(opts); + free(opts); + my_free(node); my_free(types); exit (0); /* child stops here */ @@ -1831,8 +1826,7 @@ getfs(const char *spec, const char *uuid, const char *label) if (!mc && (devname || spec)) mc = getmntfile (devname ? devname : spec); - if (devname) - my_free(devname); + my_free(devname); return mc; } diff --git a/mount/xmalloc.h b/mount/xmalloc.h index 978e541a..2fc0a7e5 100644 --- a/mount/xmalloc.h +++ b/mount/xmalloc.h @@ -5,4 +5,10 @@ extern void *xmalloc(size_t size); extern void *xrealloc(void *p, size_t size); extern char *xstrdup(const char *s); +/* + * free(p); when 'p' is 'const char *' makes gcc unhappy: + * warning: passing argument 1 of ‘free’ discards qualifiers from pointer target type + */ +#define my_free(_p) free((void *) _p) + #endif /* MOUNT_XMALLOC_H */