summaryrefslogtreecommitdiff
path: root/README.Coding
diff options
context:
space:
mode:
authorRalph Boehme <slow@samba.org>2017-08-09 15:24:41 +0200
committerRalph Boehme <slow@samba.org>2017-08-10 14:36:01 +0200
commit62925cfa6e796c546f9450846bb9e110f29139c0 (patch)
treeb9e599f709be76c7382423149405feedccbf2624 /README.Coding
parentd0381a3cf49146c0b44577a66e0c693d1edad137 (diff)
downloadsamba-62925cfa6e796c546f9450846bb9e110f29139c0.tar.gz
README.Coding: add "Error and out logic"
Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Simo <simo@samba.org> Autobuild-User(master): Ralph Böhme <slow@samba.org> Autobuild-Date(master): Thu Aug 10 14:36:01 CEST 2017 on sn-devel-144
Diffstat (limited to 'README.Coding')
-rw-r--r--README.Coding49
1 files changed, 49 insertions, 0 deletions
diff --git a/README.Coding b/README.Coding
index 19a363fa1dd..e89925cad26 100644
--- a/README.Coding
+++ b/README.Coding
@@ -445,6 +445,55 @@ The only exception is the test code that depends repeated use of calls
like CHECK_STATUS, CHECK_VAL and others.
+Error and out logic
+-------------------
+
+Don't do this:
+
+ frame = talloc_stackframe();
+
+ if (ret == LDB_SUCCESS) {
+ if (result->count == 0) {
+ ret = LDB_ERR_NO_SUCH_OBJECT;
+ } else {
+ struct ldb_message *match =
+ get_best_match(dn, result);
+ if (match == NULL) {
+ TALLOC_FREE(frame);
+ return LDB_ERR_OPERATIONS_ERROR;
+ }
+ *msg = talloc_move(mem_ctx, &match);
+ }
+ }
+
+ TALLOC_FREE(frame);
+ return ret;
+
+It should be:
+
+ frame = talloc_stackframe();
+
+ if (ret != LDB_SUCCESS) {
+ TALLOC_FREE(frame);
+ return ret;
+ }
+
+ if (result->count == 0) {
+ TALLOC_FREE(frame);
+ return LDB_ERR_NO_SUCH_OBJECT;
+ }
+
+ match = get_best_match(dn, result);
+ if (match == NULL) {
+ TALLOC_FREE(frame);
+ return LDB_ERR_OPERATIONS_ERROR;
+ }
+
+ *msg = talloc_move(mem_ctx, &match);
+ TALLOC_FREE(frame);
+ return LDB_SUCCESS;
+
+
DEBUG statements
----------------