This is the mail archive of the gdb-prs@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

cli/1566: execute_control_command may not remove its cleanups


>Number:         1566
>Category:       cli
>Synopsis:       execute_control_command may not remove its cleanups
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          patch
>Submitter-Id:   net
>Arrival-Date:   Tue Feb 24 16:18:00 UTC 2004
>Closed-Date:
>Last-Modified:
>Originator:     da_gdb@egenera.com
>Release:        GNU gdb 2004-02-24-cvs
>Organization:
>Environment:
Linux octavian 2.6.1 #2 SMP Tue Jan 20 18:46:35 EST 2004 i686 i686 i386 GNU/Linux

Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/3.2/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-checking --host=i386-redhat-linux --with-system-zlib --enable-__cxa_atexit
Thread model: posix
gcc version 3.2 20020903 (Red Hat Linux 8.0 3.2-7)

This GDB was configured as "i686-pc-linux-gnu"...Using host libthread_db library "/lib/libthread_db.so.1".
>Description:
>From code inspection, it appears that execute_control_command does not always remove the cleanups it puts on cleanup_chain.

execute_control_command depends on cleanup_chain being non-NULL when execute_control_command is called or any cleanups it puts on cleanup_chain are not removed.  

The problem is that execute_control_command initializes old_chain to NULL, and then conditionally calls do_cleanups if old_chain is non-NULL at the end of execute_control_command.  However, if the calling function has not put any cleanups on the chain previously, cleanup_chain will be NULL going into execute_control_command, therefore old_chain will still be NULL at the end of execute_control_command, and the cleanups will not be done.  This, according to the documentation, section 13.1, leads to undefined behavior.  

According to section 13.1, the correct behavior is to add a null_cleanup explicitly at the beginning of the function and unconditionally do_cleanups at the end:

struct cleanup *old = make_cleanup (null_cleanup, 0);
data = xmalloc (sizeof blah);
make_cleanup (xfree, data);
... blah blah ...
do_cleanups (old);

The attached patch makes the code conform to the documentation.  
>How-To-Repeat:
Found by code inspection; I do not know of a test case.  
>Fix:
The attached patch makes execute_control_command conform to the documentation: initializing old_chain by putting a null_cleanup on cleanup_chain and calling do_cleanups unconditionally at the end.  
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: application/octet-stream; name="execute_control_command.diff"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="execute_control_command.diff"

SW5kZXg6IGNsaS1zY3JpcHQuYwo9PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09ClJDUyBmaWxlOiAvY3ZzL3NyYy9zcmMvZ2Ri
L2NsaS9jbGktc2NyaXB0LmMsdgpyZXRyaWV2aW5nIHJldmlzaW9uIDEuMjEKZGlmZiAtdSAtcjEu
MjEgY2xpLXNjcmlwdC5jCi0tLSBjbGktc2NyaXB0LmMJMjIgRGVjIDIwMDMgMDM6NDM6MTkgLTAw
MDAJMS4yMQorKysgY2xpLXNjcmlwdC5jCTI0IEZlYiAyMDA0IDE1OjU1OjA2IC0wMDAwCkBAIC0y
OTQsNyArMjk0LDcgQEAKIHsKICAgc3RydWN0IGV4cHJlc3Npb24gKmV4cHI7CiAgIHN0cnVjdCBj
b21tYW5kX2xpbmUgKmN1cnJlbnQ7Ci0gIHN0cnVjdCBjbGVhbnVwICpvbGRfY2hhaW4gPSAwOwor
ICBzdHJ1Y3QgY2xlYW51cCAqb2xkX2NoYWluID0gbWFrZV9jbGVhbnVwIChudWxsX2NsZWFudXAs
IDApOwogICBzdHJ1Y3QgdmFsdWUgKnZhbDsKICAgc3RydWN0IHZhbHVlICp2YWxfbWFyazsKICAg
aW50IGxvb3A7CkBAIC00MjcsOCArNDI3LDcgQEAKICAgICAgIHJldHVybiBpbnZhbGlkX2NvbnRy
b2w7CiAgICAgfQogCi0gIGlmIChvbGRfY2hhaW4pCi0gICAgZG9fY2xlYW51cHMgKG9sZF9jaGFp
bik7CisgIGRvX2NsZWFudXBzIChvbGRfY2hhaW4pOwogCiAgIHJldHVybiByZXQ7CiB9Cg==


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]