473,395 Members | 2,253 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

refcounting and protecting against delete


At my workplace, we are in the process of migrating to a component
system similar to COM (but not COM itself, as we have some space and
portability requirements) that uses refcounting for resource management.

My problem is that I would like to find a way of finding out attempts to
use "delete obj" when obj is a pointer to IUnknown or a derivative.
Since this is a migration, we have a lot of existing code that uses
delete directly, and I feel that since the compiler actually has this
information at compile-time, there might be a good way to do this.

Having our own component system has the advantage that we can modify it
more freely to make this verification in a safe way.

I thought of making the destructor protected in IUnknown, but since a
lot of classes derive from it and use "delete" on other objects, this
has almost no effect.

I thought of putting a private "operator delete" in IUnknown (we do not
overload new or delete anywhere in our code), and making our
(macro-generated) implementation of Release() use "::delete", but it
seems that the code that our compilers (GCC 2.95.4, 3.x and Visual C++
7.1) generates for the classes' destructors needs access to the
"operator delete" of the classes. Annoyingly enough, this used to work
with older versions of compilers, but I guess that's how progress goes.

I am down to the point of using a bool member in my implementation of
IUnknown (for debugging only) that is initialized to false and is set to
true only when Release() calls "delete", having an assert() on it in the
destructor. But I find this rather disappointing, since this can clearly
be determined statically.

Thanks in advance for any idea!

--
Pierre Phaneuf
http://advogato.org/person/pphaneuf/

Jul 22 '05 #1
2 2068
On Sat, 03 Apr 2004 18:10:18 -0500, Pierre Phaneuf <pp@ludusdesign.com>
wrote:

At my workplace, we are in the process of migrating to a component
system similar to COM (but not COM itself, as we have some space and
portability requirements) that uses refcounting for resource management.

My problem is that I would like to find a way of finding out attempts to
use "delete obj" when obj is a pointer to IUnknown or a derivative.
Since this is a migration, we have a lot of existing code that uses
delete directly, and I feel that since the compiler actually has this
information at compile-time, there might be a good way to do this.

Having our own component system has the advantage that we can modify it
more freely to make this verification in a safe way.

I thought of making the destructor protected in IUnknown, but since a
lot of classes derive from it and use "delete" on other objects, this
has almost no effect.

I thought of putting a private "operator delete" in IUnknown (we do not
overload new or delete anywhere in our code), and making our
(macro-generated) implementation of Release() use "::delete", but it
seems that the code that our compilers (GCC 2.95.4, 3.x and Visual C++
7.1) generates for the classes' destructors needs access to the
"operator delete" of the classes.
Just a shot-in-the-dark, since no one else has offered anything yet: Can
you declare those destructors that need access to IUnknown's operator
delete to be friends of IUnknown? Perhaps there's some way of generalizing
it using a template for the friend declaration?
-leor
Annoyingly enough, this used to work
with older versions of compilers, but I guess that's how progress goes.

I am down to the point of using a bool member in my implementation of
IUnknown (for debugging only) that is initialized to false and is set to
true only when Release() calls "delete", having an assert() on it in the
destructor. But I find this rather disappointing, since this can clearly
be determined statically.

Thanks in advance for any idea!


--
Leor Zolman --- BD Software --- www.bdsoft.com
On-Site Training in C/C++, Java, Perl and Unix
C++ users: Download BD Software's free STL Error Message Decryptor at:
www.bdsoft.com/tools/stlfilt.html
Jul 22 '05 #2
On Sat, 03 Apr 2004 18:10:18 -0500, Pierre Phaneuf <pp@ludusdesign.com>
wrote:

At my workplace, we are in the process of migrating to a component
system similar to COM (but not COM itself, as we have some space and
portability requirements) that uses refcounting for resource management.

My problem is that I would like to find a way of finding out attempts to
use "delete obj" when obj is a pointer to IUnknown or a derivative.
Since this is a migration, we have a lot of existing code that uses
delete directly, and I feel that since the compiler actually has this
information at compile-time, there might be a good way to do this.

Having our own component system has the advantage that we can modify it
more freely to make this verification in a safe way.

I thought of making the destructor protected in IUnknown, but since a
lot of classes derive from it and use "delete" on other objects, this
has almost no effect.

I thought of putting a private "operator delete" in IUnknown (we do not
overload new or delete anywhere in our code), and making our
(macro-generated) implementation of Release() use "::delete", but it
seems that the code that our compilers (GCC 2.95.4, 3.x and Visual C++
7.1) generates for the classes' destructors needs access to the
"operator delete" of the classes.
Just a shot-in-the-dark, since no one else has offered anything yet: Can
you declare those destructors that need access to IUnknown's operator
delete to be friends of IUnknown? Perhaps there's some way of generalizing
it using a template for the friend declaration?
-leor
Annoyingly enough, this used to work
with older versions of compilers, but I guess that's how progress goes.

I am down to the point of using a bool member in my implementation of
IUnknown (for debugging only) that is initialized to false and is set to
true only when Release() calls "delete", having an assert() on it in the
destructor. But I find this rather disappointing, since this can clearly
be determined statically.

Thanks in advance for any idea!


--
Leor Zolman --- BD Software --- www.bdsoft.com
On-Site Training in C/C++, Java, Perl and Unix
C++ users: Download BD Software's free STL Error Message Decryptor at:
www.bdsoft.com/tools/stlfilt.html
Jul 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Nate A | last post by:
I am at the beginning stages of writing a massive database-connected business management application using the .NET framework and am becoming worried about the security of the application upon...
5
by: John | last post by:
Dear all, I've got a security question that is so difficult that "maybe" there will be no answer for it. It's regarding protecting asp code. I did write some asp code, that I sell to...
2
by: Pierre Phaneuf | last post by:
At my workplace, we are in the process of migrating to a component system similar to COM (but not COM itself, as we have some space and portability requirements) that uses refcounting for resource...
12
by: joe martin | last post by:
In recent discussions relating to what to use for a new project which integrated the work of two, previously seperate, teams we got to the subject of our respective string implementations. One team...
9
by: Darrel | last post by:
I'm learning a bit about the SWL injection issues and want to write a shared class that I can call from anywhere in my project to 'sanitize' any incoming text from textfields before sending to the...
4
by: st_ev_fe | last post by:
Hi people, I've been doing C for about 7 years now. But I'm new to C++. I've decided that C++'s operator overloading could be very handy. I'm writing something much like auto_ptr, except for...
6
by: Roman Werpachowski | last post by:
In a recent thread http://tinyurl.com/8n7fe I asked about preventing the user from deleting the object pointed to by a pointer/reference. Now I would like to ask about a different aspect of this...
17
by: (PeteCresswell) | last post by:
I've got apps where you *really* wouldn't want to delete certain items by accident, but the users just have to have a "Delete" button. My current strategies: Plan A:...
22
by: flit | last post by:
Hello All, I have a hard question, every time I look for this answer its get out from the technical domain and goes on in the moral/social domain. First, I live in third world with bad gov., bad...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.