<commit_before>#include <stdio.h>
#include <windows.h>
#include <malloc.h>

#include "org_wel4j_WindowsEventLog.h"
#include "Definitions.h"

/*******************************************************************************
**This method is called by the Java application through JNI for logging events in the
**Windows Event Log
/*******************************************************************************/
JNIEXPORT void JNICALL Java_org_wel4j_WindowsEventLog_reportEvent
  (JNIEnv *env, jclass clazz, jstring sourceName, jstring message, jint eventID, jint eventSeverity, jint eventCategory)
{
	const char *source = env->GetStringUTFChars(sourceName, 0);
	const char *msg = env->GetStringUTFChars(message, 0);
	
	DWORD wEventID = (DWORD)eventID;
	WORD  wEventSeverity = (WORD)eventSeverity;
	WORD  wEventCategory = (WORD)eventCategory;		
	
	//convert const char * to WCHAR
	WCHAR *szSource;
	szSource = (WCHAR *)malloc( 2 * strlen(source) + 2);

	for(unsigned int i = 0; i < strlen(msg); i++)
	{
		szSource[i] = (WCHAR)source[i];
	}	     
	szSource[strlen(source)] = L'\0';

    //Get the handle to the event source
	HANDLE h = RegisterEventSource(NULL,  // uses local computer 
							(LPCWSTR) szSource); // source name 

    if(h != NULL)
	{
		//convert jstring into WCHAR
		WCHAR *szMsg[1];
		szMsg[0] = (WCHAR *)malloc( 2 * strlen(msg) + 2);

		for(unsigned int i = 0; i < strlen(msg); i++)
		{
			szMsg[0][i] = (WCHAR)msg[i];
		}	     
		szMsg[0][strlen(msg)] = L'\0';

		//Log the event in the EventLog
		ReportEvent(h,           // event log handle 
					wEventSeverity,  // event type 
					wEventCategory,   // category zero 
					wEventID,        // event identifier 
					NULL,                 // no user security identifier 
					1,                    // one substitution string 
					0,                    // no data 
					(LPCWSTR *) szMsg,     // pointer to string array 
					NULL);                // pointer to data 
		
		DeregisterEventSource(h); 
		free(szMsg[0]);
	}

	env->ReleaseStringUTFChars(message, msg);
}<commit_msg>Clean-up memory allocation for application/source string.<commit_after>#include <stdio.h>
#include <windows.h>
#include <malloc.h>

#include "org_wel4j_WindowsEventLog.h"
#include "Definitions.h"

/*******************************************************************************
**This method is called by the Java application through JNI for logging events in the
**Windows Event Log
/*******************************************************************************/
JNIEXPORT void JNICALL Java_org_wel4j_WindowsEventLog_reportEvent
  (JNIEnv *env, jclass clazz, jstring sourceName, jstring message, jint eventID, jint eventSeverity, jint eventCategory)
{
	const char *source = env->GetStringUTFChars(sourceName, 0);
	const char *msg = env->GetStringUTFChars(message, 0);
	
	DWORD wEventID = (DWORD)eventID;
	WORD  wEventSeverity = (WORD)eventSeverity;
	WORD  wEventCategory = (WORD)eventCategory;		
	
	//convert const char * to WCHAR
	WCHAR *szSource;
	szSource = (WCHAR *)malloc( 2 * strlen(source) + 2);

	for(unsigned int i = 0; i < strlen(msg); i++)
	{
		szSource[i] = (WCHAR)source[i];
	}	     
	szSource[strlen(source)] = L'\0';

    //Get the handle to the event source
	HANDLE h = RegisterEventSource(NULL,  // uses local computer 
							(LPCWSTR) szSource); // source name 

    if(h != NULL)
	{
		//convert jstring into WCHAR
		WCHAR *szMsg[1];
		szMsg[0] = (WCHAR *)malloc( 2 * strlen(msg) + 2);

		for(unsigned int i = 0; i < strlen(msg); i++)
		{
			szMsg[0][i] = (WCHAR)msg[i];
		}	     
		szMsg[0][strlen(msg)] = L'\0';

		//Log the event in the EventLog
		ReportEvent(h,           // event log handle 
					wEventSeverity,  // event type 
					wEventCategory,   // category zero 
					wEventID,        // event identifier 
					NULL,                 // no user security identifier 
					1,                    // one substitution string 
					0,                    // no data 
					(LPCWSTR *) szMsg,     // pointer to string array 
					NULL);                // pointer to data 
		
		DeregisterEventSource(h); 
		free(szMsg[0]);
		free(szSource);
	}

	env->ReleaseStringUTFChars(message, msg);
	env->ReleaseStringUTFChars(sourceName, source);
}
{'fraction_non_alphanumeric': 0.18855378769888387, 'fraction_numerical': 0.009023984801709808, 'mean_word_length': 3.1538461538461537, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6269759', 'n_tokens_mistral': 1499, 'n_tokens_neox': 1315, 'n_words': 360}