<commit_before>/**
 *  Copyright (c) 2014-present, Facebook, Inc.
 *  All rights reserved.
 *
 *  This source code is licensed in accordance with the terms specified in
 *  the LICENSE file found in the root directory of this source tree.
 */

#include <osquery/process/windows/process_ops.h>
#include <osquery/utils/conversions/split.h>
#include <osquery/utils/conversions/tryto.h>
#include <osquery/utils/conversions/windows/strings.h>

namespace osquery {

std::string psidToString(PSID sid) {
  LPSTR sidOut = nullptr;
  auto ret = ConvertSidToStringSidA(sid, &sidOut);
  if (ret == 0) {
    VLOG(1) << "ConvertSidToString failed with " << GetLastError();
    return std::string("");
  }
  std::string sidString(sidOut);
  LocalFree(sidOut);
  return sidString;
}

uint32_t getUidFromSid(PSID sid) {
  auto const uid_default = static_cast<uint32_t>(-1);
  LPSTR sidString;
  if (ConvertSidToStringSidA(sid, &sidString) == 0) {
    VLOG(1) << "getUidFromSid failed ConvertSidToStringSid error " +
                   std::to_string(GetLastError());
    LocalFree(sidString);<commit_msg>Fix call to LocalFree() on uninit ptr (#6579)<commit_after>/**
 *  Copyright (c) 2014-present, Facebook, Inc.
 *  All rights reserved.
 *
 *  This source code is licensed in accordance with the terms specified in
 *  the LICENSE file found in the root directory of this source tree.
 */

#include <osquery/process/windows/process_ops.h>
#include <osquery/utils/conversions/split.h>
#include <osquery/utils/conversions/tryto.h>
#include <osquery/utils/conversions/windows/strings.h>

namespace osquery {

std::string psidToString(PSID sid) {
  LPSTR sidOut = nullptr;
  auto ret = ConvertSidToStringSidA(sid, &sidOut);
  if (ret == 0) {
    VLOG(1) << "ConvertSidToString failed with " << GetLastError();
    return std::string("");
  }
  std::string sidString(sidOut);
  LocalFree(sidOut);
  return sidString;
}

uint32_t getUidFromSid(PSID sid) {
  auto const uid_default = static_cast<uint32_t>(-1);
  LPSTR sidString = nullptr;
  if (ConvertSidToStringSidA(sid, &sidString) == 0) {
    VLOG(1) << "getUidFromSid failed ConvertSidToStringSid error " +
                   std::to_string(GetLastError());
    LocalFree(sidString);
{'fraction_non_alphanumeric': 0.12443642921550947, 'fraction_numerical': 0.013525698827772768, 'mean_word_length': 4.3086124401913874, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '961892', 'n_tokens_mistral': 761, 'n_tokens_neox': 740, 'n_words': 183}