Oberon Community Platform Forum
October 16, 2019, 03:42:08 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Memory corruption due to GC?  (Read 7671 times)
schorsch
Newbie
*
Posts: 10


« on: July 08, 2009, 09:16:13 PM »

The following problem of memory corruption due to GC in Oberon, which also exists in A2, was discovered by Trurl from forum.oberoncore.ru:

Code:
MODULE Crash;
IMPORT Log := KernelLog, Modules, Heaps;
VAR p, q: POINTER TO ARRAY 10 OF CHAR;
PROCEDURE Foo (VAR x: CHAR);
BEGIN
p := NIL;
Heaps.CollectGarbage(Modules.root);
NEW(q); q^ := 'abcdefgh';
x := '!';
END Foo;
PROCEDURE Do*;
BEGIN
Heaps.CollectGarbage(Modules.root);
NEW(p);
Foo(p[2]);
Log.String(q^); Log.Ln;
END Do;
END Crash.

SystemTools.Free Crash~
Crash.Do~

Output: ab!defgh

It looks like a bug for me, so the question is, of course, what can be done about it?
Logged
felix
Administrator
Newbie
*****
Posts: 17



WWW
« Reply #1 on: July 09, 2009, 12:57:49 PM »

Although this particular example provides a quite obvious programming error, we agree that it also shows a flaw of the runtime. In particular in a concurrent system, an error of this kind is not absolutely impossible to happen in real life.  The original pointer contained in p must be prevented from being garbage collected.

The problem is not the GC itself but rather the missing support by the compiler. We know how to deal with this problem (add a hidden pointer variable in the current context) and think about offering it with the new compiler.

best
Felix

Logged
schorsch
Newbie
*
Posts: 10


« Reply #2 on: July 13, 2009, 09:14:22 PM »

Thank you for the clarification. Of course, it's not like this flaw would prevent somebody from developing correct programs. But all Oberon fans would feel better, if such dubious behaviour would just not be possible.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!