Oh I agree that this should be the documented behavior of all varieties of
delete in the kernel, however it isn’t.
=====================
Mark Roddy
-----Original Message-----
From: Alexander Krol [mailto:xxxxx@creo.com]
Sent: Wednesday, October 27, 2004 3:55 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] RtlUnicodeStringToAnsiString problem
Returning NULL pointer on failed allocation is C idiom; ditto safely feeding
that same pointer to deallocation function (see both C and C++ standards).
Is this such a big deal to ask for this behavior to be legal and documented
in RTLXXX functions and in DDK environment in general?
-----Original Message-----
From: Roddy, Mark [mailto:xxxxx@stratus.com]
Sent: Tuesday, October 26, 2004 6:57 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] RtlUnicodeStringToAnsiString problem
Well I was going to proclaim that it would just crash and burn, but at least
on w2k3 it happens to be safe to call RtlFreeAnsiString after
RtlUnicodeStringToAnsiString fails. Relying on this behavior is rather
foolish.
=====================
Mark Roddy
-----Original Message-----
From: Alexander Krol [mailto:xxxxx@creo.com]
Sent: Tuesday, October 26, 2004 12:44 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] RtlUnicodeStringToAnsiString problem
If RUSTAS doesn’t return success, one should not touch the damned stuff,
certainly - since nowhere it is documented that it will be NULL. On the
other side, standard deallocating routines safely accept NULL, and, though
it is not documented, I would be very surprised if RtlFreeXXXString would
duffer from the bunch.
-----Original Message-----
From: Mats PETERSSON [mailto:xxxxx@3dlabs.com]
Sent: Tuesday, October 26, 2004 6:33 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] RtlUnicodeStringToAnsiString problem
xxxxx@lists.osr.com wrote on 10/26/2004 05:18:26 PM:
Buffer is allocated by RtlUnicodeStringToAnsiString because of TRUE flag.
Not the clearest of possible APIs, certainly - but documented.
I think what Mark was referring to, and what I pointed out in my excerpt
from the RUSTAS Doc’s, that if the call doesn’t return Succes, you didn’t
get any allocation, and thus YOU SHOULD NOT FREE it. Because you’ll either
try to free NULL, or worse, some random value. Freeing something that hasn’t
been allocated is a bad idea.
Now it may be OK to try to free a NULL, becasue from memory from looking at
the RtlFreeXXXString, it looked like it was checking for NULL and skipping
out. But I wouldn’t rely on such behaviour, since it may change in future
code (unless it’s specified that you can call RtlFreeXXXString with NULL in
the Doc’s). Also relying on a “Failed allocation” to be NULL is probably a
bit doubtful.
So, to keep the code clean and reliable, only free if it was a success.
–
Mats
Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
You are currently subscribed to ntdev as: xxxxx@stratus.com To
unsubscribe send a blank email to xxxxx@lists.osr.com