Fix memory managment
[platform/core/test/security-tests.git] / tests / security-server-tests / security_server_tests_client_smack.cpp
index 1c9e133..04b4f7a 100644 (file)
 #include <access_provider.h>
 #include "tests_common.h"
 #include <summary_collector.h>
-
+#include <memory.h>
 
 #define PROPER_COOKIE_SIZE 20
 
-/**
- * Unique_ptr typedef for NOSMACK version of tc06 test
- */
-void closesockfdptr(int* sockfd_ptr)
-{
-    close(*sockfd_ptr);
-}
-typedef std::unique_ptr<int, std::function<void(int*)> > SockFDUniquePtr;
 
 RUNNER_TEST_GROUP_INIT(SECURITY_SERVER_TESTS_CLIENT_SMACK)
 
@@ -149,7 +141,7 @@ RUNNER_MULTIPROCESS_TEST_SMACK(tc06_check_privilege_by_sockfd)
         int sockfd = create_new_socket();
         RUNNER_ASSERT_MSG_BT(sockfd >= 0, "create_new_socket() failed");
 
-        SockFDUniquePtr sockfd_ptr(&sockfd, closesockfdptr);
+        SockUniquePtr sockfd_ptr(&sockfd);
 
         label = security_server_get_smacklabel_sockfd(sockfd);
         RUNNER_ASSERT_MSG_BT(label != NULL, "security_server_get_smacklabel_sockfd failed");
@@ -180,7 +172,7 @@ RUNNER_MULTIPROCESS_TEST_SMACK(tc06_check_privilege_by_sockfd)
         int sockfd = connect_to_testserver();
         RUNNER_ASSERT_MSG_BT(sockfd >= 0, "connect_to_testserver() failed");
 
-        SockFDUniquePtr sockfd_ptr(&sockfd, closesockfdptr);
+        SockUniquePtr sockfd_ptr(&sockfd);
 
         label = security_server_get_smacklabel_sockfd(sockfd);
         RUNNER_ASSERT_MSG_BT(label != NULL, "security_server_get_smacklabel_sockfd failed");
@@ -239,7 +231,7 @@ RUNNER_MULTIPROCESS_TEST_SMACK(tc07_check_privilege_by_sockfd)
             int sockfd = create_new_socket();
             RUNNER_ASSERT_MSG_BT(sockfd >= 0, "create_new_socket() failed");
 
-            SockFDUniquePtr sockfd_ptr(&sockfd, closesockfdptr);
+            SockUniquePtr sockfd_ptr(&sockfd);
 
             RUNNER_ASSERT_MSG_BT(0 == smack_set_label_for_self(subject_label), "child label " << subject_label << " not set");
 
@@ -354,7 +346,7 @@ RUNNER_MULTIPROCESS_TEST_NOSMACK(tc06_check_privilege_by_sockfd_nosmack)
         int sockfd = create_new_socket();
         RUNNER_ASSERT_MSG_BT(sockfd >= 0, "create_new_socket() failed");
 
-        SockFDUniquePtr sockfd_ptr(&sockfd, closesockfdptr);
+        SockUniquePtr sockfd_ptr(&sockfd);
 
         //check if get_smacklabel_sockfd works correctly
         label = security_server_get_smacklabel_sockfd(sockfd);
@@ -385,7 +377,7 @@ RUNNER_MULTIPROCESS_TEST_NOSMACK(tc06_check_privilege_by_sockfd_nosmack)
         int sockfd = connect_to_testserver();
         RUNNER_ASSERT_MSG_BT(sockfd >= 0, "Failed to connect to server.");
 
-        SockFDUniquePtr sockfd_ptr(&sockfd, closesockfdptr);
+        SockUniquePtr sockfd_ptr(&sockfd);
 
         label = security_server_get_smacklabel_sockfd(sockfd);
         RUNNER_ASSERT_MSG_BT(label != NULL, "get_smacklabel_sockfd failed.");
@@ -425,7 +417,7 @@ RUNNER_MULTIPROCESS_TEST_NOSMACK(tc07_check_privilege_by_sockfd_nosmack)
             int sockfd = create_new_socket();
             RUNNER_ASSERT_MSG_BT(sockfd >= 0, "create_new_socket() failed");
 
-            SockFDUniquePtr sockfd_ptr(&sockfd, closesockfdptr);
+            SockUniquePtr sockfd_ptr(&sockfd);
 
             //Drop privileges
             RUNNER_ASSERT_MSG_BT(drop_root_privileges() == 0, "uid = " << getuid());
@@ -534,7 +526,7 @@ RUNNER_TEST_NOSMACK(tc18_security_server_get_smacklabel_cookie_nosmack) {
 
     //Request cookie from SS
     res = security_server_request_cookie(cookie, cookie_size);
-    std::unique_ptr<char, std::function<void(char*)> > cookie_ptr(cookie, free);
+    CookieUniquePtr cookie_ptr(cookie);
     cookie = NULL;
     RUNNER_ASSERT_MSG_BT(res == SECURITY_SERVER_API_SUCCESS,
             "Error in requesting cookie from security-server. Result: " << res);