[etherlab-dev] Ethercos: uncaught malloc fail
Len Remmerswaal
lremmerswaal at revolutioncontrols.com
Wed Apr 27 13:22:42 CEST 2011
Hi all,
I tried to run an ethercos generated code instance of a scicos application without root privileges and encountered a segmentation fault. The following patch makes visible where the error originates.
<quote>
diff -r 450be8d89459 modules/etherlab_codegen/RT_templates/rtmain.c
--- a/modules/etherlab_codegen/RT_templates/rtmain.c Thu Mar 31 14:29:05 2011 +0200
+++ b/modules/etherlab_codegen/RT_templates/rtmain.c Wed Apr 27 10:41:33 2011 +0200
@@ -307,6 +307,11 @@
int size = PREGETMEM + stackinc;
pagesize = sysconf(_SC_PAGESIZE);
buffer = malloc(size);
+ if(buffer == NULL) {
+ fprintf(stderr, "Could not allocate memory of size 0x%x (%d) in preget_mem.\n", size, size);
+ perror("malloc");
+ exit(2);
+ }
for(i=0;i< size; i+=pagesize)
{
buffer[i]=0;
</quote>
(The segmentation fault without the patch occurs at buffer[i]=0 as buffer is 0)
Running without root privileges allows my (other) users to tinker around and do some initial level of testing with their apps, after which I can install their app for them at a specific location for real time testing, without giving them full blown root rights.
The cause of malloc failing was in /etc/security/limits.conf: raising memlock from 8192 to 32768 removed the problem. I will be posting this last find in users as well.
Thanks,
Len.
More information about the etherlab-dev
mailing list