1    	/*
2    	 * Copyright (C) 2016-2026 Red Hat, Inc.  All rights reserved.
3    	 *
4    	 * Authors: Fabio M. Di Nitto <fabbione@kronosnet.org>
5    	 *
6    	 * This software licensed under GPL-2.0+
7    	 */
8    	
9    	#include "config.h"
10   	
11   	#include <errno.h>
12   	#include <stdio.h>
13   	#include <stdlib.h>
14   	#include <string.h>
15   	#include <unistd.h>
16   	
17   	#include "libknet.h"
18   	#include "internals.h"
19   	
20   	#include "test-common.h"
21   	
22   	#define TEST_NAME "api_knet_handle_free"
23   	
24   	static void test(void)
25   	{
26   		int logfd;
27   	
28   		logfd = start_logging(stdout);
29   		knet_handle_t knet_h1, knet_h[2] = {0};
30   	
31   	
32   		log_test(logfd, "Test knet_handle_free with invalid knet_h (part 1)");
33   		FAIL_ON_SUCCESS(knet_handle_free(NULL), EINVAL);
34   	
35   		knet_h1 = _ts_knet_handle_start(logfd, KNET_LOG_DEBUG, knet_h);
36   	
37   		log_test(logfd, "Test knet_handle_free with one host configured");
38   		FAIL_ON_ERR(knet_host_add(knet_h1, 1));
39   	
40   		FAIL_ON_SUCCESS(knet_handle_free(knet_h1), EBUSY);
41   	
(32) Event example_checked: Example 1: "knet_host_remove(knet_h1, 1)" has its value checked in "(_foe_res = knet_host_remove(knet_h1, 1)) != 0".
Also see events: [check_return][example_checked][example_checked][example_checked][example_assign][example_checked]
42   		FAIL_ON_ERR(knet_host_remove(knet_h1, 1));
43   	
44   		log_test(logfd, "Test knet_handle_free with invalid knet_h (part 2)");
45   		// coverity[BAD_FREE:SUPPRESS] - deliberate bad handle
46   		FAIL_ON_SUCCESS(knet_handle_free(knet_h1 + 1), EINVAL);
47   	
48   		FAIL_ON_ERR(knet_handle_free(knet_h1));
49   	
50   		TEST_EXIT_CLEAN(CONTINUE);
51   	}
52   	
53   	int main(int argc, char *argv[])
54   	{
55   		printf("[TEST] %s: Test knet handle free\n", TEST_NAME);
56   	
57   		test();
58   	
59   		TEST_EXIT(PASS);
60   	}
61