[or-cvs] r8376: As long as we are being pedantic, we may as well be extra-pe (in tor/trunk: . contrib)

nickm at seul.org nickm at seul.org
Tue Sep 12 19:00:56 UTC 2006


Author: nickm
Date: 2006-09-12 15:00:55 -0400 (Tue, 12 Sep 2006)
New Revision: 8376

Modified:
   tor/trunk/
   tor/trunk/contrib/id_to_fp.c
Log:
 r8791 at Kushana:  nickm | 2006-09-12 15:00:48 -0400
 As long as we are being pedantic, we may as well be extra-pedantic.



Property changes on: tor/trunk
___________________________________________________________________
 svk:merge ticket from /tor/trunk [r8791] on c95137ef-5f19-0410-b913-86e773d04f59

Modified: tor/trunk/contrib/id_to_fp.c
===================================================================
--- tor/trunk/contrib/id_to_fp.c	2006-09-12 18:31:03 UTC (rev 8375)
+++ tor/trunk/contrib/id_to_fp.c	2006-09-12 19:00:55 UTC (rev 8376)
@@ -14,16 +14,17 @@
 #include <stdio.h>
 #include <stdlib.h>
 
-#define die(s) do { fprintf(stderr, "%s\n", s); return 1; } while (0)
+#define die(s) do { fprintf(stderr, "%s\n", s); goto err; } while (0)
 
 int
 main(int argc, char **argv)
 {
-  BIO *b;
-  RSA *key;
-  unsigned char *buf, *bufp;
+  BIO *b = NULL;
+  RSA *key = NULL;
+  unsigned char *buf = NULL, *bufp;
   int len, i;
   unsigned char digest[20];
+  int status = 1;
 
   if (argc != 2)
     die("I want a filename");
@@ -34,7 +35,11 @@
     die("couldn't parse key");
 
   len = i2d_RSAPublicKey(key, NULL);
+  if (len < 0)
+    die("Bizarre key");
   bufp = buf = malloc(len+1);
+  if (!buf)
+    die("Out of memory");
   len = i2d_RSAPublicKey(key, &bufp);
   if (len < 0)
     die("Bizarre key");
@@ -45,6 +50,15 @@
   }
   printf("\n");
 
-  return 0;
+  status = 0;
+
+err:
+  if (buf)
+    free(buf);
+  if (key)
+    RSA_free(key);
+  if (b)
+    BIO_free(b);
+  return status;
 }
 



More information about the tor-commits mailing list