aboutsummaryrefslogtreecommitdiffstats
path: root/g10/free-packet.c
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2016-11-15 15:23:41 +0000
committerWerner Koch <[email protected]>2016-11-15 15:24:09 +0000
commit8ea3b4c4102dc67ed83d4419b7171e422fc01047 (patch)
tree6533a1d27eade4f32ea5c5edad5518da97ce16af /g10/free-packet.c
parentg10: Optimize key iteration. (diff)
downloadgnupg-8ea3b4c4102dc67ed83d4419b7171e422fc01047.tar.gz
gnupg-8ea3b4c4102dc67ed83d4419b7171e422fc01047.zip
gpg: Use usual free semantics for packet structure free functions.
* g10/free-packet.c (free_attributes): Turn function into a nop for a NULL arg. (free_user_id): Ditto. (free_compressed): Ditto. (free_encrypted): Ditto. (free_plaintext): Ditto. (release_public_key_parts): Avoid extra check for NULL. * g10/getkey.c (get_best_pubkey_byname): Ditto. -- This change avoid surprises because it is common that function named like free and taking a pointer also have similar semantics. Signed-off-by: Werner Koch <[email protected]>
Diffstat (limited to 'g10/free-packet.c')
-rw-r--r--g10/free-packet.c118
1 files changed, 71 insertions, 47 deletions
diff --git a/g10/free-packet.c b/g10/free-packet.c
index 2ca1d3bc2..6038d262e 100644
--- a/g10/free-packet.c
+++ b/g10/free-packet.c
@@ -114,11 +114,8 @@ release_public_key_parts (PKT_public_key *pk)
xfree (pk->prefs);
pk->prefs = NULL;
}
- if (pk->user_id)
- {
- free_user_id (pk->user_id);
- pk->user_id = NULL;
- }
+ free_user_id (pk->user_id);
+ pk->user_id = NULL;
if (pk->revkey)
{
xfree(pk->revkey);
@@ -293,6 +290,9 @@ free_comment( PKT_comment *rem )
void
free_attributes(PKT_user_id *uid)
{
+ if (!uid)
+ return;
+
xfree(uid->attribs);
xfree(uid->attrib_data);
@@ -304,70 +304,94 @@ free_attributes(PKT_user_id *uid)
void
free_user_id (PKT_user_id *uid)
{
- log_assert (uid->ref > 0);
- if (--uid->ref)
- return;
-
- free_attributes(uid);
- xfree (uid->prefs);
- xfree (uid->namehash);
- xfree (uid->mbox);
- xfree (uid);
+ if (!uid)
+ return;
+
+ log_assert (uid->ref > 0);
+ if (--uid->ref)
+ return;
+
+ free_attributes(uid);
+ xfree (uid->prefs);
+ xfree (uid->namehash);
+ xfree (uid->mbox);
+ xfree (uid);
}
void
free_compressed( PKT_compressed *zd )
{
- if( zd->buf ) { /* have to skip some bytes */
- /* don't have any information about the length, so
- * we assume this is the last packet */
- while( iobuf_read( zd->buf, NULL, 1<<30 ) != -1 )
- ;
+ if (!zd)
+ return;
+
+ if (zd->buf)
+ {
+ /* We need to skip some bytes. Because don't have any
+ * information about the length, so we assume this is the last
+ * packet */
+ while (iobuf_read( zd->buf, NULL, 1<<30 ) != -1)
+ ;
}
- xfree(zd);
+ xfree(zd);
}
void
free_encrypted( PKT_encrypted *ed )
{
- if( ed->buf ) { /* have to skip some bytes */
- if( ed->is_partial ) {
- while( iobuf_read( ed->buf, NULL, 1<<30 ) != -1 )
- ;
+ if (!ed)
+ return;
+
+ if (ed->buf)
+ {
+ /* We need to skip some bytes. */
+ if (ed->is_partial)
+ {
+ while (iobuf_read( ed->buf, NULL, 1<<30 ) != -1)
+ ;
}
- else {
- while( ed->len ) { /* skip the packet */
- int n = iobuf_read( ed->buf, NULL, ed->len );
- if( n == -1 )
- ed->len = 0;
- else
- ed->len -= n;
- }
+ else
+ {
+ while (ed->len)
+ {
+ /* Skip the packet. */
+ int n = iobuf_read( ed->buf, NULL, ed->len );
+ if (n == -1)
+ ed->len = 0;
+ else
+ ed->len -= n;
+ }
}
}
- xfree(ed);
+ xfree (ed);
}
void
free_plaintext( PKT_plaintext *pt )
{
- if( pt->buf ) { /* have to skip some bytes */
- if( pt->is_partial ) {
- while( iobuf_read( pt->buf, NULL, 1<<30 ) != -1 )
- ;
- }
- else {
- while( pt->len ) { /* skip the packet */
- int n = iobuf_read( pt->buf, NULL, pt->len );
- if( n == -1 )
- pt->len = 0;
- else
- pt->len -= n;
- }
+ if (!pt)
+ return;
+
+ if (pt->buf)
+ { /* We need to skip some bytes. */
+ if (pt->is_partial)
+ {
+ while (iobuf_read( pt->buf, NULL, 1<<30 ) != -1)
+ ;
+ }
+ else
+ {
+ while( pt->len )
+ { /* Skip the packet. */
+ int n = iobuf_read( pt->buf, NULL, pt->len );
+ if (n == -1)
+ pt->len = 0;
+ else
+ pt->len -= n;
+ }
}
}
- xfree(pt);
+ xfree (pt);
}
/****************