Skip to content

Commit

Permalink
Fixed sVal initialization and some potential memory leaks. (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tiihott authored Dec 13, 2022
1 parent 0d12ca0 commit 7aa0f32
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 23 deletions.
57 changes: 36 additions & 21 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 11 additions & 2 deletions src/main/c/JavaPcre.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ RegexStruct pcre2_single_jmatch(char *b, pcre2_code *re, int offset, MatchOption
PCRE2_SIZE subject_length;
PCRE2_SIZE *ovector;

RegexStruct sVal;

// constructing the uint32_t option0 parameter for match function from MatchOptionsStruct values.
uint32_t option0 = 0;
if (temp->JPCRE2_ANCHORED != 0) {
Expand Down Expand Up @@ -349,7 +351,6 @@ RegexStruct pcre2_single_jmatch(char *b, pcre2_code *re, int offset, MatchOption
*/
default: printf("Matching error %d\n", rc); break;
}
RegexStruct sVal;
sVal.numVals = 0;
sVal.vals = (char**)malloc(sizeof(char*) * 1);
sVal.names = (char**)malloc(sizeof(char*) * 1);
Expand Down Expand Up @@ -377,7 +378,7 @@ RegexStruct pcre2_single_jmatch(char *b, pcre2_code *re, int offset, MatchOption

ovector = pcre2_get_ovector_pointer(match_data);

RegexStruct sVal;

sVal.numVals = rc;
sVal.vals = (char**)malloc(sizeof(char*) * sVal.numVals);
sVal.ovector = (int*)malloc(sizeof(int) * (2 + (sVal.numVals * 2)));
Expand Down Expand Up @@ -417,6 +418,14 @@ RegexStruct pcre2_single_jmatch(char *b, pcre2_code *re, int offset, MatchOption

if (namecount == 0){
sVal.namescount = namecount;
sVal.names = (char**)malloc(sizeof(char*) * 1);
sVal.namesnum = (int*)malloc(sizeof(int) * 1);
if (sVal.names == NULL || sVal.namesnum == NULL) {
printf("Error: Out of memory\r\n");
exit(-1);
}
memset(sVal.names, 0, sizeof(char*) * 1);
memset(sVal.namesnum, 0, sizeof(int) * 1);
} else
{
PCRE2_SPTR tabptr;
Expand Down

0 comments on commit 7aa0f32

Please sign in to comment.