commit - 1dc93286a0d5b80259604b4f25021fcc5a730b5b
commit + 0ff33777febca1ac06417c976a4a3e76b68c93d8
blob - 26d4929d732b04ecaaef3c24527465fafbe94160
blob + 2835b46f51f7bc6d19e59894f5bb43d8cef4cfcd
--- src/ngircd/client.c
+++ src/ngircd/client.c
static void Generate_MyToken PARAMS(( CLIENT *Client ));
static void Adjust_Counters PARAMS(( CLIENT *Client ));
+static void Free_Client PARAMS(( CLIENT **Client ));
+
static CLIENT *Init_New_Client PARAMS((CONN_ID Idx, CLIENT *Introducer,
CLIENT *TopServer, int Type, const char *ID,
const char *User, const char *Hostname, const char *Info,
cnt = 0;
c = My_Clients;
- while( c )
- {
+ while(c) {
cnt++;
next = (CLIENT *)c->next;
- if (c->account_name)
- free(c->account_name);
- if (c->cloaked)
- free(c->cloaked);
- if (c->ipa_text)
- free(c->ipa_text);
- free( c );
+ Free_Client(&c);
c = next;
}
- if( cnt ) Log( LOG_INFO, "Freed %d client structure%s.", cnt, cnt == 1 ? "" : "s" );
+ if (cnt)
+ Log(LOG_INFO, "Freed %d client structure%s.",
+ cnt, cnt == 1 ? "" : "s");
} /* Client_Exit */
}
}
- if (c->account_name)
- free(c->account_name);
- if (c->cloaked)
- free(c->cloaked);
- if (c->ipa_text)
- free(c->ipa_text);
- free( c );
+ Free_Client(&c);
break;
}
last = c;
} /* MyCount */
+/**
+ * Allocate and initialize new CLIENT strcuture.
+ *
+ * @return Pointer to CLIENT structure or NULL on error.
+ */
static CLIENT *
New_Client_Struct( void )
{
c->mytoken = -1;
return c;
-} /* New_Client */
+}
+
+/**
+ * Free a CLIENT structure and its member variables.
+ */
+static void
+Free_Client(CLIENT **Client)
+{
+ assert(Client != NULL);
+ assert(*Client != NULL);
+ if ((*Client)->account_name)
+ free((*Client)->account_name);
+ if ((*Client)->cloaked)
+ free((*Client)->cloaked);
+ if ((*Client)->ipa_text)
+ free((*Client)->ipa_text);
+ free(*Client);
+ *Client = NULL;
+}
+
static void
Generate_MyToken( CLIENT *Client )
{