+2010-01-20 Felix Zielcke <fzielcke@z-51.de>
+
+ * util/misc.c (make_system_path_relative_to_its_root): Change the work
+ around for handling "/" to the correct fix. Fix a memory leak. Use
+ xstrdup instead of strdup.
+
2010-01-20 Vladimir Serbinenko <phcoder@gmail.com>
* conf/mips.rmk (kernel_img_HEADERS): Add env_private.h
grub_util_error ("failed to get canonical path of %s", path);
len = strlen (p) + 1;
- buf = strdup (p);
+ buf = xstrdup (p);
free (p);
if (stat (buf, &st) < 0)
grub_util_error ("cannot stat %s: %s", buf, strerror (errno));
- buf2 = strdup (buf);
+ buf2 = xstrdup (buf);
num = st.st_dev;
/* This loop sets offset to the number of chars of the root
/* buf is another filesystem; we found it. */
if (st.st_dev != num)
{
- /* offset == 0 means path given is the mount point. */
+ /* offset == 0 means path given is the mount point.
+ This works around special-casing of "/" in Un*x. This function never
+ prints trailing slashes (so that its output can be appended a slash
+ unconditionally). Each slash in is considered a preceding slash, and
+ therefore the root directory is an empty string. */
if (offset == 0)
{
free (buf);
free (buf2);
- return strdup ("/");
+ return xstrdup ("");
}
else
break;
buf2[len - 1] = '\0';
len--;
}
- return buf2;
+ if (len > 1)
+ return buf2;
+ else
+ {
+ /* This means path given is just a backslash. As above
+ we have to return an empty string. */
+ free (buf2);
+ return xtrdup ("");
+ }
}
}
free (buf);
- buf3 = strdup (buf2 + offset);
+ buf3 = xstrdup (buf2 + offset);
free (buf2);
len = strlen (buf3);
len--;
}
- /* This works around special-casing of "/" in Un*x. This function never
- prints trailing slashes (so that its output can be appended a slash
- unconditionally). Each slash in is considered a preceding slash, and
- therefore the root directory is an empty string. */
- if (!strcmp (buf3, "/"))
- buf3[0] = '\0';
-
return buf3;
}