Commit 49c4fceb authored by Laurent THOMAS's avatar Laurent THOMAS

fix memory error: too early paramters read, then free (before end of usage

parent 7ca1f045
...@@ -96,39 +96,24 @@ static void read_pipe(int p, char *b, int size) { ...@@ -96,39 +96,24 @@ static void read_pipe(int p, char *b, int size) {
} }
} }
static int baseRunTimeCommand(char* cmd, size_t cmdSize) { static int baseRunTimeCommand(char* cmd) {
FILE *fp; return system(cmd);
size_t retSize = 0;
fp = popen(cmd, "r");
if(fp) {
memset(cmd, 0, cmdSize);
retSize = fread(cmd, 1, cmdSize, fp);
fclose(fp);
} else {
LOG_D(HW,"%s:%d:%s: Cannot open %s\n", __FILE__, __LINE__, __FUNCTION__, cmd);
}
if (retSize == 0) {
return 0;
}
return atoi(cmd);
} }
int checkIfFedoraDistribution(void) { int checkIfFedoraDistribution(void) {
char cmd[200]; char cmd[200];
memset(cmd, 0, 200); memset(cmd, 0, 200);
sprintf(cmd, "cat /etc/os-release | grep ID_LIKE | grep -ic fedora || true"); sprintf(cmd, "cat /etc/os-release | grep ID_LIKE | grep -ic fedora");
return baseRunTimeCommand(cmd, 200); return baseRunTimeCommand(cmd);
} }
int checkIfGenericKernelOnFedora(void) { int checkIfGenericKernelOnFedora(void) {
char cmd[200]; char cmd[200];
memset(cmd, 0, 200); memset(cmd, 0, 200);
sprintf(cmd, "uname -a | grep -c rt || true"); sprintf(cmd, "uname -a | grep -c rt");
return (1 - baseRunTimeCommand(cmd, 200)); return (1 - baseRunTimeCommand(cmd));
} }
int checkIfInsideContainer(void) { int checkIfInsideContainer(void) {
...@@ -136,8 +121,8 @@ int checkIfInsideContainer(void) { ...@@ -136,8 +121,8 @@ int checkIfInsideContainer(void) {
int res = 0; int res = 0;
memset(cmd, 0, 200); memset(cmd, 0, 200);
sprintf(cmd, "cat /proc/self/cgroup | egrep -c 'libpod|podman|kubepods' || true"); sprintf(cmd, "cat /proc/self/cgroup | egrep -c 'libpod|podman|kubepods'");
res = baseRunTimeCommand(cmd, 200); res = baseRunTimeCommand(cmd);
if (res > 0) if (res > 0)
return 1; return 1;
else else
...@@ -255,19 +240,21 @@ void threadCreate(pthread_t* t, void * (*func)(void*), void * param, char* name, ...@@ -255,19 +240,21 @@ void threadCreate(pthread_t* t, void * (*func)(void*), void * param, char* name,
AssertFatal(ret==0,"ret: %d, errno: %d\n",ret, errno); AssertFatal(ret==0,"ret: %d, errno: %d\n",ret, errno);
ret=pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED); ret=pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
AssertFatal(ret==0,"ret: %d, errno: %d\n",ret, errno); AssertFatal(ret==0,"ret: %d, errno: %d\n",ret, errno);
/*
if (checkIfFedoraDistribution()) if (checkIfFedoraDistribution())
if (checkIfGenericKernelOnFedora()) if (checkIfGenericKernelOnFedora())
if (checkIfInsideContainer()) if (checkIfInsideContainer())
settingPriority = 0; */
settingPriority = 0;
if (settingPriority) { if (settingPriority) {
ret=pthread_attr_setschedpolicy(&attr, SCHED_OAI); ret=pthread_attr_setschedpolicy(&attr, SCHED_OAI);
AssertFatal(ret==0,"ret: %d, errno: %d\n",ret, errno); AssertFatal(ret==0,"ret: %d, errno: %d\n",ret, errno);
if(priority<sched_get_priority_min(SCHED_OAI) || priority>sched_get_priority_max(SCHED_FIFO)) { if(priority<sched_get_priority_min(SCHED_OAI) || priority>sched_get_priority_max(SCHED_OAI)) {
LOG_E(TMR,"Prio not possible: %d, min is %d, max: %d, forced in the range\n", LOG_E(TMR,"Prio not possible: %d, min is %d, max: %d, forced in the range\n",
priority, priority,
sched_get_priority_min(SCHED_OAI), sched_get_priority_min(SCHED_OAI),
sched_get_priority_max(SCHED_OAI)); sched_get_priority_max(SCHED_OAI));
if(priority<sched_get_priority_min(SCHED_OAI)) if(priority<sched_get_priority_min(SCHED_OAI))
priority=sched_get_priority_min(SCHED_OAI); priority=sched_get_priority_min(SCHED_OAI);
if(priority>sched_get_priority_max(SCHED_OAI)) if(priority>sched_get_priority_max(SCHED_OAI))
...@@ -279,12 +266,13 @@ void threadCreate(pthread_t* t, void * (*func)(void*), void * param, char* name, ...@@ -279,12 +266,13 @@ void threadCreate(pthread_t* t, void * (*func)(void*), void * param, char* name,
ret=pthread_attr_setschedparam(&attr, &sparam); ret=pthread_attr_setschedparam(&attr, &sparam);
AssertFatal(ret==0,"ret: %d, errno: %d\n",ret, errno); AssertFatal(ret==0,"ret: %d, errno: %d\n",ret, errno);
} }
ret=pthread_create(t, &attr, func, param); ret=pthread_create(t, &attr, func, param);
AssertFatal(ret==0,"ret: %d, errno: %d\n",ret, errno); AssertFatal(ret==0,"ret: %d, errno: %d\n",ret, errno);
pthread_setname_np(*t, name); pthread_setname_np(*t, name);
if (affinity != -1 ) { if (affinity != -1 ) {
abort();
cpu_set_t cpuset; cpu_set_t cpuset;
CPU_ZERO(&cpuset); CPU_ZERO(&cpuset);
CPU_SET(affinity, &cpuset); CPU_SET(affinity, &cpuset);
......
...@@ -823,7 +823,7 @@ int main( int argc, char **argv ) { ...@@ -823,7 +823,7 @@ int main( int argc, char **argv ) {
} }
printf("About to call end_configmodule() from %s() %s:%d\n", __FUNCTION__, __FILE__, __LINE__); printf("About to call end_configmodule() from %s() %s:%d\n", __FUNCTION__, __FILE__, __LINE__);
end_configmodule(); //end_configmodule();
printf("Called end_configmodule() from %s() %s:%d\n", __FUNCTION__, __FILE__, __LINE__); printf("Called end_configmodule() from %s() %s:%d\n", __FUNCTION__, __FILE__, __LINE__);
// wait for end of program // wait for end of program
printf("TYPE <CTRL-C> TO TERMINATE\n"); printf("TYPE <CTRL-C> TO TERMINATE\n");
......
...@@ -812,9 +812,8 @@ void RCconfig_NRRRC(MessageDef *msg_p, uint32_t i, gNB_RRC_INST *rrc) { ...@@ -812,9 +812,8 @@ void RCconfig_NRRRC(MessageDef *msg_p, uint32_t i, gNB_RRC_INST *rrc) {
paramdef_t GNBParams[] = GNBPARAMS_DESC; paramdef_t GNBParams[] = GNBPARAMS_DESC;
paramlist_def_t GNBParamList = {GNB_CONFIG_STRING_GNB_LIST,NULL,0}; paramlist_def_t GNBParamList = {GNB_CONFIG_STRING_GNB_LIST,NULL,0};
NR_ServingCellConfigCommon_t *scc = calloc(1,sizeof(NR_ServingCellConfigCommon_t)); NR_ServingCellConfigCommon_t *scc = calloc(1,sizeof(*scc));
uint64_t ssb_bitmap=0xff; uint64_t ssb_bitmap=0xff;
memset((void*)scc,0,sizeof(NR_ServingCellConfigCommon_t));
prepare_scc(scc); prepare_scc(scc);
paramdef_t SCCsParams[] = SCCPARAMS_DESC(scc); paramdef_t SCCsParams[] = SCCPARAMS_DESC(scc);
paramlist_def_t SCCsParamList = {GNB_CONFIG_STRING_SERVINGCELLCONFIGCOMMON, NULL, 0}; paramlist_def_t SCCsParamList = {GNB_CONFIG_STRING_SERVINGCELLCONFIGCOMMON, NULL, 0};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment