Skip to content
Snippets Groups Projects
Commit 426123d2 authored by Lucas Magalhães's avatar Lucas Magalhães
Browse files

Merge branch 'fix_valgrind' into 'master'

E3-1197: Fix possible memory issues

See merge request e3/e3-require!131
parents b60a9122 fb57df48
No related branches found
No related tags found
No related merge requests found
...@@ -637,7 +637,8 @@ static int compareVersions(const char *found, const char *request, ...@@ -637,7 +637,8 @@ static int compareVersions(const char *found, const char *request,
semver_t *sv_found, *sv_request; semver_t *sv_found, *sv_request;
int match; int match;
debug("require: compareVersions(found=%s, request=%s)\n", found, request); debug("require: compareVersions(found=%s, request=%s)\n", found,
request ? request : "");
if (request == NULL || request[0] == 0) { if (request == NULL || request[0] == 0) {
debug("require: compareVersions: MATCH empty version requested\n"); debug("require: compareVersions: MATCH empty version requested\n");
...@@ -895,6 +896,7 @@ static int require_priv( ...@@ -895,6 +896,7 @@ static int require_priv(
const char *versionstr /* "-<version>" or "" (for old style only */ const char *versionstr /* "-<version>" or "" (for old style only */
) { ) {
int status; int status;
int returnvalue = 0;
const char *loaded = NULL; const char *loaded = NULL;
const char *found = NULL; const char *found = NULL;
HMODULE libhandle; HMODULE libhandle;
...@@ -979,8 +981,8 @@ static int require_priv( ...@@ -979,8 +981,8 @@ static int require_priv(
/* Search for module in driverpath */ /* Search for module in driverpath */
for (dirname = driverpath; dirname != NULL; dirname = end) { for (dirname = driverpath; dirname != NULL; dirname = end) {
/* get one directory from driverpath */ /* get one directory from driverpath */
int dirlen; int dirlen = 0;
int modulediroffs; int modulediroffs = 0;
DIR_HANDLE dir; DIR_HANDLE dir;
DIR_ENTRY direntry; DIR_ENTRY direntry;
...@@ -1019,7 +1021,7 @@ static int require_priv( ...@@ -1019,7 +1021,7 @@ static int require_priv(
/* Look for highest matching version. */ /* Look for highest matching version. */
if (requireDebug) if (requireDebug)
printf("require: checking version %s against required %s\n", printf("require: checking version %s against required %s\n",
currentFilename, version); currentFilename, version ? version : "");
switch ((status = compareVersions(currentFilename, version, FALSE))) { switch ((status = compareVersions(currentFilename, version, FALSE))) {
case MATCH: /* all given numbers match. */ case MATCH: /* all given numbers match. */
...@@ -1028,7 +1030,7 @@ static int require_priv( ...@@ -1028,7 +1030,7 @@ static int require_priv(
if (requireDebug) if (requireDebug)
printf("require: %s %s may match %s\n", module, currentFilename, printf("require: %s %s may match %s\n", module, currentFilename,
version); version ? version : "");
/* Check if it has our EPICS version and architecture. */ /* Check if it has our EPICS version and architecture. */
/* Even if it has no library, at least it has a dep file in the /* Even if it has no library, at least it has a dep file in the
...@@ -1138,6 +1140,7 @@ static int require_priv( ...@@ -1138,6 +1140,7 @@ static int require_priv(
else else
fprintf(stderr, "Module %s%s%s not available\n", module, fprintf(stderr, "Module %s%s%s not available\n", module,
version ? " version " : "", version ? version : ""); version ? " version " : "", version ? version : "");
if (founddir) free(founddir);
return ifexists ? 0 : -1; return ifexists ? 0 : -1;
} }
...@@ -1207,7 +1210,8 @@ static int require_priv( ...@@ -1207,7 +1210,8 @@ static int require_priv(
fprintf(stderr, fprintf(stderr,
"Requested %s version %s not available, found only %s.\n", "Requested %s version %s not available, found only %s.\n",
module, version, found); module, version, found);
return -1; returnvalue = -1;
goto require_priv_error;
} }
/* load dbd file */ /* load dbd file */
...@@ -1227,7 +1231,8 @@ static int require_priv( ...@@ -1227,7 +1231,8 @@ static int require_priv(
printf("Loading dbd file %s\n", filename); printf("Loading dbd file %s\n", filename);
if (dbLoadDatabase(filename, NULL, NULL) != 0) { if (dbLoadDatabase(filename, NULL, NULL) != 0) {
fprintf(stderr, "Error loading %s\n", filename); fprintf(stderr, "Error loading %s\n", filename);
return -1; returnvalue = -1;
goto require_priv_error;
} }
/* when dbd is loaded call register function */ /* when dbd is loaded call register function */
...@@ -1263,12 +1268,18 @@ static int require_priv( ...@@ -1263,12 +1268,18 @@ static int require_priv(
putenvprintf("TEMPLATES=%s", globalTemplates); putenvprintf("TEMPLATES=%s", globalTemplates);
} }
if (founddir) free(founddir);
/* no need to execute startup script twice if not with new arguments */ /* no need to execute startup script twice if not with new arguments */
if (loaded && args == NULL) { if (loaded && args == NULL) {
return 0; return 0;
} }
return status; return status;
require_priv_error:
if (founddir) free(founddir);
return returnvalue;
} }
static const iocshFuncDef requireDef = { static const iocshFuncDef requireDef = {
......
...@@ -49,6 +49,7 @@ int runScript(const char *filename, const char *args) { ...@@ -49,6 +49,7 @@ int runScript(const char *filename, const char *args) {
MAC_HANDLE *mac = NULL; MAC_HANDLE *mac = NULL;
FILE *file = NULL; FILE *file = NULL;
char *line_raw = NULL; char *line_raw = NULL;
char *aux_pointer = NULL;
char *line_exp = NULL; char *line_exp = NULL;
long line_raw_size = 256; long line_raw_size = 256;
long line_exp_size = line_raw_size; long line_exp_size = line_raw_size;
...@@ -125,8 +126,9 @@ int runScript(const char *filename, const char *args) { ...@@ -125,8 +126,9 @@ int runScript(const char *filename, const char *args) {
while (line_raw[(len = (long)strlen(line_raw)) - 1] != '\n' && while (line_raw[(len = (long)strlen(line_raw)) - 1] != '\n' &&
!feof(file)) { !feof(file)) {
if (runScriptDebug) printf("runScript partial line: \"%s\"\n", line_raw); if (runScriptDebug) printf("runScript partial line: \"%s\"\n", line_raw);
if ((line_raw = realloc(line_raw, line_raw_size *= 2)) == NULL) if ((aux_pointer = realloc(line_raw, line_raw_size *= 2)) == NULL)
goto error; goto error;
line_raw = aux_pointer;
if (fgets(line_raw + len, line_raw_size - len, file) == NULL) break; if (fgets(line_raw + len, line_raw_size - len, file) == NULL) break;
} }
while (len > 0 && isspace((unsigned char)line_raw[len - 1])) while (len > 0 && isspace((unsigned char)line_raw[len - 1]))
......
...@@ -52,6 +52,7 @@ semver_t *parse_semver(const char *version) { ...@@ -52,6 +52,7 @@ semver_t *parse_semver(const char *version) {
} }
if (regcomp(&compiled, version_regex, REG_EXTENDED)) { if (regcomp(&compiled, version_regex, REG_EXTENDED)) {
regfree(&compiled);
return NULL; return NULL;
} }
...@@ -67,5 +68,6 @@ semver_t *parse_semver(const char *version) { ...@@ -67,5 +68,6 @@ semver_t *parse_semver(const char *version) {
s->version_str[groups[revision_ix].rm_so - 1] = 0; s->version_str[groups[revision_ix].rm_so - 1] = 0;
} }
} }
regfree(&compiled);
return s; return s;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment