From 69526997e5636211824f8c041a9e57d039cc62f4 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Mon, 7 May 2012 11:56:39 +0200 Subject: doc: Fixes for the talloc best practices tutorial. --- lib/talloc/doc/tutorial_bestpractices.dox | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'lib/talloc') diff --git a/lib/talloc/doc/tutorial_bestpractices.dox b/lib/talloc/doc/tutorial_bestpractices.dox index 034d63aa11..3634446743 100644 --- a/lib/talloc/doc/tutorial_bestpractices.dox +++ b/lib/talloc/doc/tutorial_bestpractices.dox @@ -4,18 +4,18 @@ The following sections contain several best practices and good manners that were found by the Samba and SSSD developers over the years. -These will help you to write better code, easier to debug and with as few -(hopefully none) memory leaks as possible. +These will help you to write code which is better, easier to debug and with as +few (hopefully none) memory leaks as possible. @section bp-hierarchy Keep the context hierarchy steady The talloc is a hierarchy memory allocator. The hierarchy nature is what makes -the programming more error proof. It makes the memory easier to manage and free. -Therefore, the first thing we should have on our mind is: always project our -data structures into the talloc context hierarchy. +the programming more error proof. It makes the memory easier to manage and to +free. Therefore, the first thing we should have on our mind is: always project +your data structures into the talloc context hierarchy. That means if we have a structure, we should always use it as a parent context -for its elements. This way we will not encounter any troubles when freeing this +for its elements. This way we will not encounter any troubles when freeing the structure or when changing its parent. The same rule applies for arrays. For example, the structure user from section @ref context-hierarchy @@ -26,7 +26,7 @@ should be created with the context hierarchy illustrated on the next image. @section bp-tmpctx Every function should use its own context It is a good practice to create a temporary talloc context at the function -beginning and free this context just before the return statement. All the data +beginning and free the context just before the return statement. All the data must be allocated on this context or on its children. This ensures that no memory leaks are created as long as we do not forget to free the temporary context. @@ -99,8 +99,8 @@ using NULL as the parameter for talloc_new() function. Take a look at the following example: @code -char * create_user_filter(TALLOC_CTX *mem_ctx, - uid_t uid, const char *username) +char *create_user_filter(TALLOC_CTX *mem_ctx, + uid_t uid, const char *username) { char *filter = NULL; char *sanitized_username = NULL; @@ -189,4 +189,4 @@ errno_t handle_request(TALLOC_CTX mem_ctx) } @endcode -*/ \ No newline at end of file +*/ -- cgit