Ver código fonte

Switch from calloc() to malloc()+memset() to match the practices used

almost everywhere else.
tags/v0.9.3
Michael Brown 18 anos atrás
pai
commit
06630a3036
2 arquivos alterados com 6 adições e 2 exclusões
  1. 4
    1
      src/net/netdevice.c
  2. 2
    1
      src/net/tcp.c

+ 4
- 1
src/net/netdevice.c Ver arquivo

@@ -178,9 +178,12 @@ struct pk_buff * netdev_rx_dequeue ( struct net_device *netdev ) {
178 178
  */
179 179
 struct net_device * alloc_netdev ( size_t priv_size ) {
180 180
 	struct net_device *netdev;
181
+	size_t total_len;
181 182
 
182
-	netdev = calloc ( 1, sizeof ( *netdev ) + priv_size );
183
+	total_len = ( sizeof ( *netdev ) + priv_size );
184
+	netdev = malloc ( total_len );
183 185
 	if ( netdev ) {
186
+		memset ( netdev, 0, total_len );
184 187
 		INIT_LIST_HEAD ( &netdev->references );
185 188
 		INIT_LIST_HEAD ( &netdev->tx_queue );
186 189
 		INIT_LIST_HEAD ( &netdev->rx_queue );

+ 2
- 1
src/net/tcp.c Ver arquivo

@@ -149,9 +149,10 @@ tcp_dump_flags ( struct tcp_connection *conn, unsigned int flags ) {
149 149
 static struct tcp_connection * alloc_tcp ( void ) {
150 150
 	struct tcp_connection *conn;
151 151
 
152
-	conn = calloc ( 1, sizeof ( *conn ) );
152
+	conn = malloc ( sizeof ( *conn ) );
153 153
 	if ( conn ) {
154 154
 		DBGC ( conn, "TCP %p allocated\n", conn );
155
+		memset ( conn, 0, sizeof ( *conn ) );
155 156
 		conn->tcp_state = conn->prev_tcp_state = TCP_CLOSED;
156 157
 		conn->snd_seq = random();
157 158
 		conn->timer.expired = tcp_expired;

Carregando…
Cancelar
Salvar