Fix memleak on keys with more than one user id
authorPanu Matilainen <Panu Matilainen pmatilai@redhat.com>
Wed, 13 Jul 2011 13:19:01 +0000 (16:19 +0300)
committerPanu Matilainen <Panu Matilainen pmatilai@redhat.com>
Wed, 13 Jul 2011 13:19:01 +0000 (16:19 +0300)
- This is not "correct", we should permit more than one user id.
  Leaking memory is still worse than not leaking, corrent behavior
  or not.

rpmio/rpmpgp.c

index ebd126c..01e74e4 100644 (file)
@@ -1044,9 +1044,9 @@ static int pgpPrtUserID(pgpTag tag, const uint8_t *h, size_t hlen,
        fprintf(stderr, " \"%.*s\"", (int)hlen, (const char *)h);
     pgpPrtNL();
     if (_digp) {
-       char * t;
-       _digp->userid = t = memcpy(xmalloc(hlen+1), h, hlen);
-       t[hlen] = '\0';
+       free(_digp->userid);
+       _digp->userid = memcpy(xmalloc(hlen+1), h, hlen);
+       _digp->userid[hlen] = '\0';
     }
     return 0;
 }