The following commit has been merged in the master branch:
commit e411455bf64cb62369a9503fa1b2c1ffb935e198
Author: Guillem Jover <[email protected]>
Date:   Thu Sep 24 20:42:11 2009 +0200

    libdpkg: Do not allocate memory for buffer md5 hash result
    
    Expect the caller to pass a suitable buffer to store the result.

diff --git a/lib/dpkg/buffer.c b/lib/dpkg/buffer.c
index b20e860..691309c 100644
--- a/lib/dpkg/buffer.c
+++ b/lib/dpkg/buffer.c
@@ -40,7 +40,7 @@
 
 struct buffer_write_md5ctx {
        struct MD5Context ctx;
-       char **hash;
+       char *hash;
 };
 
 static void
@@ -74,7 +74,7 @@ buffer_md5_done(buffer_data_t data)
        int i;
 
        ctx = (struct buffer_write_md5ctx *)data->data.ptr;
-       *ctx->hash = hash = m_malloc(MD5HASHLEN + 1);
+       hash = ctx->hash;
        MD5Final(digest, &ctx->ctx);
        for (i = 0; i < 16; ++i) {
                sprintf(hash, "%02x", *p++);
diff --git a/src/configure.c b/src/configure.c
index 94a14bb..6342871 100644
--- a/src/configure.c
+++ b/src/configure.c
@@ -56,7 +56,7 @@ static int conffoptcells[2][2] = {
        { cfo_keep,             cfo_prompt_keep },      /* User edited. */
 };
 
-static void md5hash(struct pkginfo *pkg, char **hashbuf, const char *fn);
+static void md5hash(struct pkginfo *pkg, char *hashbuf, const char *fn);
 static void copyfileperm(const char* source, const char* target);
 static void showdiff(const char* old, const char* new);
 static void suspend(void);
@@ -69,7 +69,7 @@ deferred_configure_conffile(struct pkginfo *pkg, struct 
conffile *conff)
 {
        struct filenamenode *usenode;
        static const char EMPTY_HASH[] = "-";
-       char *currenthash = NULL, *newdisthash = NULL;
+       char currenthash[MD5HASHLEN + 1], newdisthash[MD5HASHLEN + 1];
        int useredited, distedited;
        enum conffopt what;
        struct stat stab;
@@ -84,7 +84,7 @@ deferred_configure_conffile(struct pkginfo *pkg, struct 
conffile *conff)
                conff->hash = EMPTY_HASH;
                return;
        }
-       md5hash(pkg, &currenthash, cdr.buf);
+       md5hash(pkg, currenthash, cdr.buf);
 
        varbufreset(&cdr2);
        varbufaddstr(&cdr2, cdr.buf);
@@ -100,7 +100,7 @@ deferred_configure_conffile(struct pkginfo *pkg, struct 
conffile *conff)
                        return;
                ohshite(_("unable to stat new dist conffile `%.250s'"), 
cdr2.buf);
        }
-       md5hash(pkg, &newdisthash, cdr2.buf);
+       md5hash(pkg, newdisthash, cdr2.buf);
 
        /* Copy the permissions from the installed version to the new
         * distributed version. */
@@ -204,8 +204,6 @@ deferred_configure_conffile(struct pkginfo *pkg, struct 
conffile *conff)
        conff->hash = nfstrsave(newdisthash);
        modstatdb_note(pkg);
 
-       free(newdisthash);
-       free(currenthash);
        varbuffree(&cdr);
        varbuffree(&cdr2);
 }
@@ -425,10 +423,13 @@ int conffderef(struct pkginfo *pkg, struct varbuf 
*result, const char *in) {
        }
 }
     
-/* Generate a MD5 hash for fn and store it in *hashbuf. Memory is allocated
- * by this function and should be freed manually.
+/*
+ * Generate a MD5 hash for fn and store it in hashbuf, which needs to be
+ * at least MD5HASHLEN + 1 characters long.
  */
-static void md5hash(struct pkginfo *pkg, char **hashbuf, const char *fn) {
+static void
+md5hash(struct pkginfo *pkg, char *hashbuf, const char *fn)
+{
        static int fd;
 
        fd=open(fn,O_RDONLY);
@@ -439,11 +440,11 @@ static void md5hash(struct pkginfo *pkg, char **hashbuf, 
const char *fn) {
                pop_cleanup(ehflag_normaltidy); /* fd= open(cdr.buf) */
                close(fd);
        } else if (errno==ENOENT) {
-               *hashbuf = m_strdup(NONEXISTENTFLAG);
+               strcpy(hashbuf, NONEXISTENTFLAG);
        } else {
                warning(_("%s: unable to open conffile %s for hash: %s"),
                        pkg->name, fn, strerror(errno));
-               *hashbuf = m_strdup("-");
+               strcpy(hashbuf, "-");
        }
 }
 

-- 
dpkg's main repository


-- 
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]

Reply via email to