diff mbox

[PATCHv2] resource leak fixes

Message ID 1412258277-13901-1-git-send-email-maxim.uvarov@linaro.org
State Accepted
Commit b936952ca36e9787641e09ee16b1af17881522b0
Headers show

Commit Message

Maxim Uvarov Oct. 2, 2014, 1:57 p.m. UTC
Fix Coverity warnings about resource leaks.
Coverity CIDs: 56713, 5611, 56707, 56705, 56703.

Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
---
 example/ipsec/odp_ipsec.c                  | 1 +
 platform/linux-generic/odp_packet_socket.c | 1 +
 test/api_test/odp_ring_test.c              | 5 ++++-
 test/api_test/odp_timer_ping.c             | 4 ++--
 4 files changed, 8 insertions(+), 3 deletions(-)

Comments

Mike Holmes Oct. 2, 2014, 6:58 p.m. UTC | #1
On 2 October 2014 09:57, Maxim Uvarov <maxim.uvarov@linaro.org> wrote:

> Fix Coverity warnings about resource leaks.
> Coverity CIDs: 56713, 5611, 56707, 56705, 56703.
>
> Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
>
Reviewed-by: Mike Holmes <mike.holmes@linaro.org>
Coverity lists them as fixed with the patch applied

> ---
>  example/ipsec/odp_ipsec.c                  | 1 +
>  platform/linux-generic/odp_packet_socket.c | 1 +
>  test/api_test/odp_ring_test.c              | 5 ++++-
>  test/api_test/odp_timer_ping.c             | 4 ++--
>  4 files changed, 8 insertions(+), 3 deletions(-)
>
> diff --git a/example/ipsec/odp_ipsec.c b/example/ipsec/odp_ipsec.c
> index cd94d9a..b7544ce 100644
> --- a/example/ipsec/odp_ipsec.c
> +++ b/example/ipsec/odp_ipsec.c
> @@ -243,6 +243,7 @@ int query_mac_address(char *intf, uint8_t *src_mac)
>         memset(&ifr, 0, sizeof(ifr));
>         snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "%s", intf);
>         if (ioctl(sd, SIOCGIFHWADDR, &ifr) < 0) {
> +               close(sd);
>                 ODP_ERR("Error: ioctl() failed for %s\n", intf);
>                 return -1;
>         }
> diff --git a/platform/linux-generic/odp_packet_socket.c
> b/platform/linux-generic/odp_packet_socket.c
> index e173c31..d0fb10e 100644
> --- a/platform/linux-generic/odp_packet_socket.c
> +++ b/platform/linux-generic/odp_packet_socket.c
> @@ -504,6 +504,7 @@ static int mmap_pkt_socket(void)
>
>         ret = setsockopt(sock, SOL_PACKET, PACKET_VERSION, &ver,
> sizeof(ver));
>         if (ret == -1) {
> +               close(sock);
>                 perror("pkt_socket() - setsockopt(PACKET_VERSION)");
>                 return -1;
>         }
> diff --git a/test/api_test/odp_ring_test.c b/test/api_test/odp_ring_test.c
> index d75c30b..1da5845 100644
> --- a/test/api_test/odp_ring_test.c
> +++ b/test/api_test/odp_ring_test.c
> @@ -261,8 +261,10 @@ static int producer_fn(void)
>
>         do {
>                 i = odph_ring_mp_enqueue_bulk(r_stress, src, MAX_BULK);
> -               if (i == 0)
> +               if (i == 0) {
> +                       free(src);
>                         return 0;
> +               }
>         } while (1);
>  }
>
> @@ -288,6 +290,7 @@ static int consumer_fn(void)
>                                         return -1;
>                                 }
>                         }
> +                       free(src);
>                         printf("\n Test OK !\n");
>                         return 0;
>                 }
> diff --git a/test/api_test/odp_timer_ping.c
> b/test/api_test/odp_timer_ping.c
> index 7406a45..65e3834 100644
> --- a/test/api_test/odp_timer_ping.c
> +++ b/test/api_test/odp_timer_ping.c
> @@ -167,8 +167,7 @@ static int send_ping_request(struct sockaddr_in *addr)
>         sd = socket(PF_INET, SOCK_RAW, proto->p_proto);
>         if (sd < 0) {
>                 ODP_ERR("Sender socket open failed\n");
> -               err = -1;
> -               goto err;
> +               return -1;
>         }
>
>         if (setsockopt(sd, SOL_IP, IP_TTL, &val, sizeof(val)) != 0) {
> @@ -240,6 +239,7 @@ static int send_ping_request(struct sockaddr_in *addr)
>         }
>
>  err:
> +       close(sd);
>         return err;
>  }
>
> --
> 1.8.5.1.163.gd7aced9
>
>
> _______________________________________________
> lng-odp mailing list
> lng-odp@lists.linaro.org
> http://lists.linaro.org/mailman/listinfo/lng-odp
>
Mike Holmes Oct. 7, 2014, 5:04 p.m. UTC | #2
ping

On 2 October 2014 14:58, Mike Holmes <mike.holmes@linaro.org> wrote:

>
>
> On 2 October 2014 09:57, Maxim Uvarov <maxim.uvarov@linaro.org> wrote:
>
>> Fix Coverity warnings about resource leaks.
>> Coverity CIDs: 56713, 5611, 56707, 56705, 56703.
>>
>> Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
>>
> Reviewed-by: Mike Holmes <mike.holmes@linaro.org>
> Coverity lists them as fixed with the patch applied
>
>> ---
>>  example/ipsec/odp_ipsec.c                  | 1 +
>>  platform/linux-generic/odp_packet_socket.c | 1 +
>>  test/api_test/odp_ring_test.c              | 5 ++++-
>>  test/api_test/odp_timer_ping.c             | 4 ++--
>>  4 files changed, 8 insertions(+), 3 deletions(-)
>>
>> diff --git a/example/ipsec/odp_ipsec.c b/example/ipsec/odp_ipsec.c
>> index cd94d9a..b7544ce 100644
>> --- a/example/ipsec/odp_ipsec.c
>> +++ b/example/ipsec/odp_ipsec.c
>> @@ -243,6 +243,7 @@ int query_mac_address(char *intf, uint8_t *src_mac)
>>         memset(&ifr, 0, sizeof(ifr));
>>         snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "%s", intf);
>>         if (ioctl(sd, SIOCGIFHWADDR, &ifr) < 0) {
>> +               close(sd);
>>                 ODP_ERR("Error: ioctl() failed for %s\n", intf);
>>                 return -1;
>>         }
>> diff --git a/platform/linux-generic/odp_packet_socket.c
>> b/platform/linux-generic/odp_packet_socket.c
>> index e173c31..d0fb10e 100644
>> --- a/platform/linux-generic/odp_packet_socket.c
>> +++ b/platform/linux-generic/odp_packet_socket.c
>> @@ -504,6 +504,7 @@ static int mmap_pkt_socket(void)
>>
>>         ret = setsockopt(sock, SOL_PACKET, PACKET_VERSION, &ver,
>> sizeof(ver));
>>         if (ret == -1) {
>> +               close(sock);
>>                 perror("pkt_socket() - setsockopt(PACKET_VERSION)");
>>                 return -1;
>>         }
>> diff --git a/test/api_test/odp_ring_test.c b/test/api_test/odp_ring_test.c
>> index d75c30b..1da5845 100644
>> --- a/test/api_test/odp_ring_test.c
>> +++ b/test/api_test/odp_ring_test.c
>> @@ -261,8 +261,10 @@ static int producer_fn(void)
>>
>>         do {
>>                 i = odph_ring_mp_enqueue_bulk(r_stress, src, MAX_BULK);
>> -               if (i == 0)
>> +               if (i == 0) {
>> +                       free(src);
>>                         return 0;
>> +               }
>>         } while (1);
>>  }
>>
>> @@ -288,6 +290,7 @@ static int consumer_fn(void)
>>                                         return -1;
>>                                 }
>>                         }
>> +                       free(src);
>>                         printf("\n Test OK !\n");
>>                         return 0;
>>                 }
>> diff --git a/test/api_test/odp_timer_ping.c
>> b/test/api_test/odp_timer_ping.c
>> index 7406a45..65e3834 100644
>> --- a/test/api_test/odp_timer_ping.c
>> +++ b/test/api_test/odp_timer_ping.c
>> @@ -167,8 +167,7 @@ static int send_ping_request(struct sockaddr_in *addr)
>>         sd = socket(PF_INET, SOCK_RAW, proto->p_proto);
>>         if (sd < 0) {
>>                 ODP_ERR("Sender socket open failed\n");
>> -               err = -1;
>> -               goto err;
>> +               return -1;
>>         }
>>
>>         if (setsockopt(sd, SOL_IP, IP_TTL, &val, sizeof(val)) != 0) {
>> @@ -240,6 +239,7 @@ static int send_ping_request(struct sockaddr_in *addr)
>>         }
>>
>>  err:
>> +       close(sd);
>>         return err;
>>  }
>>
>> --
>> 1.8.5.1.163.gd7aced9
>>
>>
>> _______________________________________________
>> lng-odp mailing list
>> lng-odp@lists.linaro.org
>> http://lists.linaro.org/mailman/listinfo/lng-odp
>>
>
>
>
> --
> *Mike Holmes*
> Linaro  Sr Technical Manager
> LNG - ODP
>
Maxim Uvarov Oct. 7, 2014, 9:20 p.m. UTC | #3
That is merged.

Maxim.

On 10/07/2014 09:04 PM, Mike Holmes wrote:
> ping
>
> On 2 October 2014 14:58, Mike Holmes <mike.holmes@linaro.org 
> <mailto:mike.holmes@linaro.org>> wrote:
>
>
>
>     On 2 October 2014 09:57, Maxim Uvarov <maxim.uvarov@linaro.org
>     <mailto:maxim.uvarov@linaro.org>> wrote:
>
>         Fix Coverity warnings about resource leaks.
>         Coverity CIDs: 56713, 5611, 56707, 56705, 56703.
>
>         Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org
>         <mailto:maxim.uvarov@linaro.org>>
>
>     Reviewed-by: Mike Holmes <mike.holmes@linaro.org
>     <mailto:mike.holmes@linaro.org>>
>     Coverity lists them as fixed with the patch applied
>
>         ---
>          example/ipsec/odp_ipsec.c                  | 1 +
>          platform/linux-generic/odp_packet_socket.c | 1 +
>          test/api_test/odp_ring_test.c              | 5 ++++-
>          test/api_test/odp_timer_ping.c             | 4 ++--
>          4 files changed, 8 insertions(+), 3 deletions(-)
>
>         diff --git a/example/ipsec/odp_ipsec.c b/example/ipsec/odp_ipsec.c
>         index cd94d9a..b7544ce 100644
>         --- a/example/ipsec/odp_ipsec.c
>         +++ b/example/ipsec/odp_ipsec.c
>         @@ -243,6 +243,7 @@ int query_mac_address(char *intf, uint8_t
>         *src_mac)
>                 memset(&ifr, 0, sizeof(ifr));
>                 snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "%s", intf);
>                 if (ioctl(sd, SIOCGIFHWADDR, &ifr) < 0) {
>         +               close(sd);
>                         ODP_ERR("Error: ioctl() failed for %s\n", intf);
>                         return -1;
>                 }
>         diff --git a/platform/linux-generic/odp_packet_socket.c
>         b/platform/linux-generic/odp_packet_socket.c
>         index e173c31..d0fb10e 100644
>         --- a/platform/linux-generic/odp_packet_socket.c
>         +++ b/platform/linux-generic/odp_packet_socket.c
>         @@ -504,6 +504,7 @@ static int mmap_pkt_socket(void)
>
>                 ret = setsockopt(sock, SOL_PACKET, PACKET_VERSION,
>         &ver, sizeof(ver));
>                 if (ret == -1) {
>         +               close(sock);
>                         perror("pkt_socket() -
>         setsockopt(PACKET_VERSION)");
>                         return -1;
>                 }
>         diff --git a/test/api_test/odp_ring_test.c
>         b/test/api_test/odp_ring_test.c
>         index d75c30b..1da5845 100644
>         --- a/test/api_test/odp_ring_test.c
>         +++ b/test/api_test/odp_ring_test.c
>         @@ -261,8 +261,10 @@ static int producer_fn(void)
>
>                 do {
>                         i = odph_ring_mp_enqueue_bulk(r_stress, src,
>         MAX_BULK);
>         -               if (i == 0)
>         +               if (i == 0) {
>         +                       free(src);
>                                 return 0;
>         +               }
>                 } while (1);
>          }
>
>         @@ -288,6 +290,7 @@ static int consumer_fn(void)
>                                                 return -1;
>                                         }
>                                 }
>         +                       free(src);
>                                 printf("\n Test OK !\n");
>                                 return 0;
>                         }
>         diff --git a/test/api_test/odp_timer_ping.c
>         b/test/api_test/odp_timer_ping.c
>         index 7406a45..65e3834 100644
>         --- a/test/api_test/odp_timer_ping.c
>         +++ b/test/api_test/odp_timer_ping.c
>         @@ -167,8 +167,7 @@ static int send_ping_request(struct
>         sockaddr_in *addr)
>                 sd = socket(PF_INET, SOCK_RAW, proto->p_proto);
>                 if (sd < 0) {
>                         ODP_ERR("Sender socket open failed\n");
>         -               err = -1;
>         -               goto err;
>         +               return -1;
>                 }
>
>                 if (setsockopt(sd, SOL_IP, IP_TTL, &val, sizeof(val))
>         != 0) {
>         @@ -240,6 +239,7 @@ static int send_ping_request(struct
>         sockaddr_in *addr)
>                 }
>
>          err:
>         +       close(sd);
>                 return err;
>          }
>
>         --
>         1.8.5.1.163.gd7aced9
>
>
>         _______________________________________________
>         lng-odp mailing list
>         lng-odp@lists.linaro.org <mailto:lng-odp@lists.linaro.org>
>         http://lists.linaro.org/mailman/listinfo/lng-odp
>
>
>
>
>     -- 
>     *Mike Holmes*
>     Linaro  Sr Technical Manager
>     LNG - ODP
>
>
>
>
> -- 
> *Mike Holmes*
> Linaro  Sr Technical Manager
> LNG - ODP
diff mbox

Patch

diff --git a/example/ipsec/odp_ipsec.c b/example/ipsec/odp_ipsec.c
index cd94d9a..b7544ce 100644
--- a/example/ipsec/odp_ipsec.c
+++ b/example/ipsec/odp_ipsec.c
@@ -243,6 +243,7 @@  int query_mac_address(char *intf, uint8_t *src_mac)
 	memset(&ifr, 0, sizeof(ifr));
 	snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "%s", intf);
 	if (ioctl(sd, SIOCGIFHWADDR, &ifr) < 0) {
+		close(sd);
 		ODP_ERR("Error: ioctl() failed for %s\n", intf);
 		return -1;
 	}
diff --git a/platform/linux-generic/odp_packet_socket.c b/platform/linux-generic/odp_packet_socket.c
index e173c31..d0fb10e 100644
--- a/platform/linux-generic/odp_packet_socket.c
+++ b/platform/linux-generic/odp_packet_socket.c
@@ -504,6 +504,7 @@  static int mmap_pkt_socket(void)
 
 	ret = setsockopt(sock, SOL_PACKET, PACKET_VERSION, &ver, sizeof(ver));
 	if (ret == -1) {
+		close(sock);
 		perror("pkt_socket() - setsockopt(PACKET_VERSION)");
 		return -1;
 	}
diff --git a/test/api_test/odp_ring_test.c b/test/api_test/odp_ring_test.c
index d75c30b..1da5845 100644
--- a/test/api_test/odp_ring_test.c
+++ b/test/api_test/odp_ring_test.c
@@ -261,8 +261,10 @@  static int producer_fn(void)
 
 	do {
 		i = odph_ring_mp_enqueue_bulk(r_stress, src, MAX_BULK);
-		if (i == 0)
+		if (i == 0) {
+			free(src);
 			return 0;
+		}
 	} while (1);
 }
 
@@ -288,6 +290,7 @@  static int consumer_fn(void)
 					return -1;
 				}
 			}
+			free(src);
 			printf("\n Test OK !\n");
 			return 0;
 		}
diff --git a/test/api_test/odp_timer_ping.c b/test/api_test/odp_timer_ping.c
index 7406a45..65e3834 100644
--- a/test/api_test/odp_timer_ping.c
+++ b/test/api_test/odp_timer_ping.c
@@ -167,8 +167,7 @@  static int send_ping_request(struct sockaddr_in *addr)
 	sd = socket(PF_INET, SOCK_RAW, proto->p_proto);
 	if (sd < 0) {
 		ODP_ERR("Sender socket open failed\n");
-		err = -1;
-		goto err;
+		return -1;
 	}
 
 	if (setsockopt(sd, SOL_IP, IP_TTL, &val, sizeof(val)) != 0) {
@@ -240,6 +239,7 @@  static int send_ping_request(struct sockaddr_in *addr)
 	}
 
 err:
+	close(sd);
 	return err;
 }