diff options
author | Alexander Shishkin <virtuoso@slind.org> | 2010-10-21 00:24:05 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-10-21 00:24:05 +0200 |
commit | a7027bf89e57d59958641ee7033e0f85f26ef412 (patch) | |
tree | 31e60559d25894c6992e00138607c85150d38ae3 /coreutils | |
parent | 894ef6003242bcb0b5ae4ba766475ed048b9f5ca (diff) | |
download | busybox-w32-a7027bf89e57d59958641ee7033e0f85f26ef412.tar.gz busybox-w32-a7027bf89e57d59958641ee7033e0f85f26ef412.tar.bz2 busybox-w32-a7027bf89e57d59958641ee7033e0f85f26ef412.zip |
stat: remove superfluous setXXent() calls, plug memory leak
function old new delta
print_stat 875 865 -10
Signed-off-by: Alexander Shishkin <virtuoso@slind.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'coreutils')
-rw-r--r-- | coreutils/stat.c | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/coreutils/stat.c b/coreutils/stat.c index 777197292..d176d07ea 100644 --- a/coreutils/stat.c +++ b/coreutils/stat.c | |||
@@ -247,14 +247,12 @@ static void FAST_FUNC print_stat(char *pformat, const char m, | |||
247 | strcat(pformat, "lu"); | 247 | strcat(pformat, "lu"); |
248 | printf(pformat, (unsigned long) statbuf->st_uid); | 248 | printf(pformat, (unsigned long) statbuf->st_uid); |
249 | } else if (m == 'U') { | 249 | } else if (m == 'U') { |
250 | setpwent(); | ||
251 | pw_ent = getpwuid(statbuf->st_uid); | 250 | pw_ent = getpwuid(statbuf->st_uid); |
252 | printfs(pformat, (pw_ent != NULL) ? pw_ent->pw_name : "UNKNOWN"); | 251 | printfs(pformat, (pw_ent != NULL) ? pw_ent->pw_name : "UNKNOWN"); |
253 | } else if (m == 'g') { | 252 | } else if (m == 'g') { |
254 | strcat(pformat, "lu"); | 253 | strcat(pformat, "lu"); |
255 | printf(pformat, (unsigned long) statbuf->st_gid); | 254 | printf(pformat, (unsigned long) statbuf->st_gid); |
256 | } else if (m == 'G') { | 255 | } else if (m == 'G') { |
257 | setgrent(); | ||
258 | gw_ent = getgrgid(statbuf->st_gid); | 256 | gw_ent = getgrgid(statbuf->st_gid); |
259 | printfs(pformat, (gw_ent != NULL) ? gw_ent->gr_name : "UNKNOWN"); | 257 | printfs(pformat, (gw_ent != NULL) ? gw_ent->gr_name : "UNKNOWN"); |
260 | } else if (m == 't') { | 258 | } else if (m == 't') { |
@@ -591,20 +589,20 @@ static bool do_stat(const char *filename, const char *format) | |||
591 | # endif | 589 | # endif |
592 | } else { | 590 | } else { |
593 | char *linkname = NULL; | 591 | char *linkname = NULL; |
594 | |||
595 | struct passwd *pw_ent; | 592 | struct passwd *pw_ent; |
596 | struct group *gw_ent; | 593 | struct group *gw_ent; |
597 | setgrent(); | 594 | |
598 | gw_ent = getgrgid(statbuf.st_gid); | 595 | gw_ent = getgrgid(statbuf.st_gid); |
599 | setpwent(); | ||
600 | pw_ent = getpwuid(statbuf.st_uid); | 596 | pw_ent = getpwuid(statbuf.st_uid); |
601 | 597 | ||
602 | if (S_ISLNK(statbuf.st_mode)) | 598 | if (S_ISLNK(statbuf.st_mode)) |
603 | linkname = xmalloc_readlink_or_warn(filename); | 599 | linkname = xmalloc_readlink_or_warn(filename); |
604 | if (linkname) | 600 | if (linkname) { |
605 | printf(" File: '%s' -> '%s'\n", filename, linkname); | 601 | printf(" File: '%s' -> '%s'\n", filename, linkname); |
606 | else | 602 | free(linkname); |
603 | } else { | ||
607 | printf(" File: '%s'\n", filename); | 604 | printf(" File: '%s'\n", filename); |
605 | } | ||
608 | 606 | ||
609 | printf(" Size: %-10llu\tBlocks: %-10llu IO Block: %-6lu %s\n" | 607 | printf(" Size: %-10llu\tBlocks: %-10llu IO Block: %-6lu %s\n" |
610 | "Device: %llxh/%llud\tInode: %-10llu Links: %-5lu", | 608 | "Device: %llxh/%llud\tInode: %-10llu Links: %-5lu", |