mirror of
https://dev.iopsys.eu/bbf/icwmp.git
synced 2025-12-10 07:44:41 +01:00
Fix memory leak issue of regcomp
This commit is contained in:
parent
969686c8e6
commit
d2007e8606
1 changed files with 19 additions and 5 deletions
|
|
@ -174,18 +174,27 @@ static char *get_software_module_object_eq(char *param1, char *val1, char *param
|
|||
if (err)
|
||||
return NULL;
|
||||
|
||||
struct cwmp_dm_parameter *param_value;
|
||||
struct cwmp_dm_parameter *param_value = NULL;
|
||||
char instance[8] = {0};
|
||||
regex_t regex1 = {};
|
||||
regex_t regex2 = {};
|
||||
bool softwaremodule_filter_param = false;
|
||||
char regstr1[256];
|
||||
snprintf(regstr1, sizeof(regstr1), "^Device.SoftwareModules.DeploymentUnit.[0-9][0-9]*.%s$",param1);
|
||||
regcomp(®ex1, regstr1, 0);
|
||||
|
||||
snprintf(regstr1, sizeof(regstr1), "^Device.SoftwareModules.DeploymentUnit.[1-9][0-9]*.%s$", param1);
|
||||
if (regcomp(®ex1, regstr1, 0) != 0) {
|
||||
CWMP_LOG(ERROR, "Failed to compile regex1: %s", regstr1);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (param2) {
|
||||
char regstr2[256];
|
||||
snprintf(regstr2, sizeof(regstr2), "^Device.SoftwareModules.DeploymentUnit.[0-9][0-9]*.%s$",param2);
|
||||
regcomp(®ex2, regstr2, 0);
|
||||
snprintf(regstr2, sizeof(regstr2), "^Device.SoftwareModules.DeploymentUnit.[1-9][0-9]*.%s$", param2);
|
||||
if (regcomp(®ex2, regstr2, 0) != 0) {
|
||||
CWMP_LOG(ERROR, "Failed to compile regex2: %s", regstr2);
|
||||
regfree(®ex1);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
list_for_each_entry (param_value, sw_parameters, list) {
|
||||
|
|
@ -201,6 +210,11 @@ static char *get_software_module_object_eq(char *param1, char *val1, char *param
|
|||
snprintf(instance, (size_t)(strchr(param_value->name + strlen("Device.SoftwareModules.DeploymentUnit."), '.') - param_value->name - strlen("Device.SoftwareModules.DeploymentUnit.") + 1), "%s", (char *)(param_value->name + strlen("Device.SoftwareModules.DeploymentUnit.")));
|
||||
break;
|
||||
}
|
||||
|
||||
regfree(®ex1);
|
||||
if (param2) {
|
||||
regfree(®ex2);
|
||||
}
|
||||
return (strlen(instance) > 0) ? strdup(instance) : NULL;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue