Red Hat Bugzilla – Bug 135446
Stack array allocation dynamically resolves size on destruction
Last modified: 2007-11-30 17:07:04 EST
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4.3)
Description of problem:
Destruction of local array of objects dynamically resolves array size;
the should be stored when array is allocated.
For example, allocate and array on the stack with:
When the variable goes out of scope, the array elements are
destructed. But the length of the array comes from invoking f() again!
The compiler should store the allocated size rather than invoke the
sizing function again as the return value could be different.
Version-Release number of selected component (if applicable):
Steps to Reproduce:
1. Compile attached program with g++
2. Run a.out
Actual Results: Program crashes because sizing function is called a
second time. Perhaps this is a heavy handed demonstration, but that
was the original problem I faced.
Expected Results: No crash. Proper deallocation.
Failure occurs with:
g++ (GCC) 3.2.3 20030502 (Red Hat Linux 3.2.3-42).
Problem does not occur with:
g++ (GCC) 3.3.4 20040623 (Gentoo Linux 3.3.4-r1, ssp-3.3.2-2, pie-8.7.6)
Created attachment 105086 [details]
C++ code to demonstrate bug. With comments.
Just FYI, VLAs are not ISO C++.
Seems this was in GCC 3.3 around 2003-04-23 by a patch that was meant
as optimization, not a bug fix, though I don't think such a patch
is suitable for GCC 3.2.3-RH.
Will look into alternatives.
This bug is filed against RHEL 3, which is in maintenance phase.
During the maintenance phase, only security errata and select mission
critical bug fixes will be released for enterprise products. Since
this bug does not meet that criteria, it is now being closed.
For more information of the RHEL errata support policy, please visit:
If you feel this bug is indeed mission critical, please contact your
support representative. You may be asked to provide detailed
information on how this bug is affecting you.