Fix resource leak
[platform/core/security/privilege-info.git] / src / privilege_info.c
index 37c31d3..a300b00 100755 (executable)
@@ -262,15 +262,15 @@ int privilege_info_get_privacy_privilege_status(const char *privilege, bool *sta
        TryReturn(smack_new_label_from_self(&smack_label) != -1, *status = true, PRVINFO_ERROR_INTERNAL_ERROR, "[PRVINFO_ERROR_INTERNAL_ERROR] smack_new_label_from_self() failed.");
 
        cynara *cynara = NULL;
-       TryReturn(cynara_initialize(&cynara, NULL) == CYNARA_API_SUCCESS, *status = true; cynara = NULL, PRVINFO_ERROR_INTERNAL_ERROR, "[PRVINFO_ERROR_INTERNAL_ERROR] cynara_initialize() failed.");
+       TryReturn(cynara_initialize(&cynara, NULL) == CYNARA_API_SUCCESS, *status = true; cynara = NULL; free(smack_label), PRVINFO_ERROR_INTERNAL_ERROR, "[PRVINFO_ERROR_INTERNAL_ERROR] cynara_initialize() failed.");
 
        char *session = NULL;
        session = cynara_session_from_pid(getpid());
-       TryReturn(session != NULL, *status = true; cynara_finish(cynara), PRVINFO_ERROR_INTERNAL_ERROR, "[PRVINFO_ERROR_INTERNAL_ERROR] cynara_session_from_pid() failed");
+       TryReturn(session != NULL, *status = true; cynara_finish(cynara); free(smack_label), PRVINFO_ERROR_INTERNAL_ERROR, "[PRVINFO_ERROR_INTERNAL_ERROR] cynara_session_from_pid() failed");
 
        char uid[UIDMAXLEN];
        int result = snprintf(uid, UIDMAXLEN, "%d", getuid());
-       TryReturn(uid != NULL && result > 0, *status = true; free(session); cynara_finish(cynara), PRVINFO_ERROR_INTERNAL_ERROR, "[PRVINFO_ERROR_INTERNAL_ERROR] snprintf() for uid failed.");
+       TryReturn(uid != NULL && result > 0, *status = true; free(session); cynara_finish(cynara); free(smack_label), PRVINFO_ERROR_INTERNAL_ERROR, "[PRVINFO_ERROR_INTERNAL_ERROR] snprintf() for uid failed.");
 
        result = cynara_simple_check(cynara, smack_label, session, uid, privilege);
        int ret = PRVINFO_ERROR_NONE;
@@ -278,6 +278,7 @@ int privilege_info_get_privacy_privilege_status(const char *privilege, bool *sta
        cynara_finish(cynara);
 
        LOGD("result of cynara_check(cynara %s, session, %s, %s) result = %d", smack_label, uid, privilege, result);
+       free(smack_label);
        if (result == CYNARA_API_ACCESS_DENIED) {
                *status = false;
        } else if (result == CYNARA_API_ACCESS_ALLOWED) {