[PATCH] Fix up discard-const warnings in s4 and tries to remove "discard_const_p"s/"CONST DISCARD"s in both s3 and s4

Volker Lendecke Volker.Lendecke at SerNet.DE
Tue Sep 29 07:08:23 MDT 2009


On Tue, Sep 29, 2009 at 02:56:18PM +0200, Matthias Dieter Wallnöfer wrote:
> Where exactly lies the problem here? Memory? (So I can understand the  
> problem)

For example this one: 

diff --git a/source3/smbd/msdfs.c b/source3/smbd/msdfs.c
index 4a338fa..eda1876 100644 (file)
--- a/source3/smbd/msdfs.c
+++ b/source3/smbd/msdfs.c
@@ -1764,7 +1764,7 @@ NTSTATUS
resolve_dfspath_wcard(TALLOC_CTX *ctx,
                 * Once srvstr_get_path() uses talloc it'll
                 * be a talloced ptr anyway.
                 */
-               *pp_name_out = CONST_DISCARD(char *,name_in);
+               *pp_name_out = talloc_strdup(ctx, name_in);
        }
        return status;
 }

While probably the right thing to do, this introduces a bug:
You don't check if the talloc_strdup actually worked. You
need to check if talloc_strdup has returned NULL and in that
case return NT_STATUS_NO_MEMORY from resolve_dfspath_wcard().

To be honest, I don't really like these mass-conversions if
they are not done very, very carefully. This one I just
picked is around in many places.

Also, you need to make very certain that when you use a
talloc_strdup or talloc_memdup that this is not in a hot
codepath that might duplicate a lot of memory and thus
create a performance hit. Also, you need to make very
certain that you memdup/strdup on the right memory context.
If by accident you put memory to a long-lived context, you
have created a memory leak.

Have you checked these points in all instances?

Thanks,

Volker

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: Digital signature
URL: <http://lists.samba.org/pipermail/samba-technical/attachments/20090929/8b9116c1/attachment.pgp>


More information about the samba-technical mailing list