[BusyBox-cvs] svn commit: trunk/busybox/coreutils
landley at busybox.net
landley at busybox.net
Sat Apr 30 05:11:58 UTC 2005
Author: landley
Date: 2005-04-29 23:11:57 -0600 (Fri, 29 Apr 2005)
New Revision: 10207
Log:
On Wednesday 13 April 2005 09:12 pm, Shaun Jackman wrote:
> This patch fixes a memory leak in hash_file by using the BUFFER macros
> instead of xmalloc. Please apply.
Modified:
trunk/busybox/coreutils/md5_sha1_sum.c
Changeset:
Modified: trunk/busybox/coreutils/md5_sha1_sum.c
===================================================================
--- trunk/busybox/coreutils/md5_sha1_sum.c 2005-04-30 03:49:37 UTC (rev 10206)
+++ trunk/busybox/coreutils/md5_sha1_sum.c 2005-04-30 05:11:57 UTC (rev 10207)
@@ -49,34 +49,21 @@
static uint8_t *hash_file(const char *filename, uint8_t hash_algo)
{
- uint8_t *hash_value_bin;
- uint8_t *hash_value = NULL;
- uint8_t hash_length;
- int src_fd;
-
- if (strcmp(filename, "-") == 0) {
- src_fd = STDIN_FILENO;
+ int src_fd = strcmp(filename, "-") == 0 ? STDIN_FILENO :
+ open(filename, O_RDONLY);
+ if (src_fd == -1) {
+ bb_perror_msg("%s", filename);
+ return NULL;
} else {
- src_fd = open(filename, O_RDONLY);
+ uint8_t *hash_value;
+ RESERVE_CONFIG_UBUFFER(hash_value_bin, 20);
+ hash_value = hash_fd(src_fd, -1, hash_algo, hash_value_bin) != -2 ?
+ hash_bin_to_hex(hash_value_bin, hash_algo == HASH_MD5 ? 16 : 20) :
+ NULL;
+ RELEASE_CONFIG_BUFFER(hash_value_bin);
+ close(src_fd);
+ return hash_value;
}
-
- if (hash_algo == HASH_MD5) {
- hash_length = 16;
- } else {
- hash_length = 20;
- }
-
- hash_value_bin = xmalloc(hash_length);
-
- if ((src_fd != -1) && (hash_fd(src_fd, -1, hash_algo, hash_value_bin) != -2)) {
- hash_value = hash_bin_to_hex(hash_value_bin, hash_length);
- } else {
- bb_perror_msg("%s", filename);
- }
-
- close(src_fd);
-
- return(hash_value);
}
/* This could become a common function for md5 as well, by using md5_stream */
More information about the busybox-cvs
mailing list