git:master:5940e759: regex: free unused tmp pkg memory for reloaded patterns – sr-dev

Module: kamailio
Branch: master
Commit: 5940e759a754644d29e4145eea648ede45b4b356
URL: github.com/kamailio/kamailio/commit/5940e759a754644d29e4145eea648ed…

Author: Daniel-Constantin Mierla
Committer: Daniel-Constantin Mierla
Date: 2017-11-02T08:42:58+01:00

regex: free unused tmp pkg memory for reloaded patterns

– use memset instead of for loop to init allocated memory to 0
– few bits of code formatting

—

Modified: src/modules/regex/regex_mod.c

—

Diff:
github.com/kamailio/kamailio/commit/5940e759a754644d29e4145eea648ed…
Patch:
github.com/kamailio/kamailio/commit/5940e759a754644d29e4145eea648ed…

—

diff –git a/src/modules/regex/regex_mod.c b/src/modules/regex/regex_mod.c
index b83af7a2c9..9d5cbf6cfd 100644
— a/src/modules/regex/regex_mod.c
+++ b/src/modules/regex/regex_mod.c
@@ -271,17 +271,17 @@ static int load_pcres(int action)
fclose(f);
goto err;
}
– memset(patterns[i], ‘\0’, group_max_size);
+ memset(patterns[i], 0, group_max_size);
}

/* Read the file and extract the patterns */
– memset(line, ‘\0′, FILE_MAX_LINE);
+ memset(line, 0, FILE_MAX_LINE);
i = -1;
while (fgets(line, FILE_MAX_LINE, f) != NULL) {

/* Ignore comments and lines starting by space, tab, CR, LF */
if(isspace(line[0]) || line[0]==’#’) {
– memset(line, ‘\0’, FILE_MAX_LINE);
+ memset(line, 0, FILE_MAX_LINE);
continue;
}

@@ -303,7 +303,7 @@ static int load_pcres(int action)
}
/* Start the regular expression with ‘(‘ */
patterns[i][0] = ‘(‘;
– memset(line, ‘\0’, FILE_MAX_LINE);
+ memset(line, 0, FILE_MAX_LINE);
continue;
}

@@ -329,7 +329,7 @@ static int load_pcres(int action)
/* Append the line to the current pattern */
memcpy(patterns[i]+strlen(patterns[i]), line, strlen(line));

– memset(line, ‘\0’, FILE_MAX_LINE);
+ memset(line, 0, FILE_MAX_LINE);
}
num_pcres_tmp = i + 1;

@@ -370,7 +370,8 @@ static int load_pcres(int action)
/* Log the group patterns */
LM_INFO(“num groups = %d\n”, num_pcres_tmp);
for (i=0; i < num_pcres_tmp; i++) {
– LM_INFO(“%s (size = %i)\n”, i,
patterns[i], i, (int)strlen(patterns[i]));
+ LM_INFO(“%s (size = %i)\n”, i,
patterns[i],
+ i, (int)strlen(patterns[i]));
}

/* Temporal pointer of pcres */
@@ -385,14 +386,17 @@ static int load_pcres(int action)
/* Compile the patters */
for (i=0; i

Read more here: Source link