lib: Fix samba-util dep in "errors" module
authorVolker Lendecke <vl@samba.org>
Wed, 17 Sep 2014 13:09:52 +0000 (15:09 +0200)
committerVolker Lendecke <vl@samba.org>
Thu, 18 Sep 2014 18:36:11 +0000 (20:36 +0200)
This piece of code pulls in talloc_stackframe and smb_panic into what
should be a very simple mapping library. I'm trying to reduce our
dependencies right now a bit, and I think the use cases that this fixes
(unknown NTSTATUS together with double nt_errstr() calls in the same
DEBUG) are rare enough that this is not justified.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Martin Schwenke <martin@meltin.net>
libcli/util/nterr.c
libcli/util/wscript_build

index 9f90f7a95fa785d011d8a1a233d9686177463f13..dbf399b82afc9b8e51fa075e203f6ad12fde0004 100644 (file)
@@ -3905,8 +3905,8 @@ NTSTATUS nt_status_squash(NTSTATUS nt_status)
 
 const char *nt_errstr(NTSTATUS nt_code)
 {
+       static char msg[20];
        int idx = 0;
-       char *result;
 
        while (nt_errs[idx].nt_errstr != NULL) {
                if (NT_STATUS_V(nt_errs[idx].nt_errcode) ==
@@ -3916,22 +3916,14 @@ const char *nt_errstr(NTSTATUS nt_code)
                idx++;
        }
 
-       if (!talloc_stackframe_exists()) {
-               /* prevent memory leaks from talloc_tos() by using a
-                * static area. This means the caller will overwrite
-                * the string with subsequent calls, which can cause
-                * display of the wrong error. If that happens the
-                * caller should have a talloc stackframe
-                */
-               static char msg[20];
-               snprintf(msg, sizeof(msg), "NT code 0x%08x", NT_STATUS_V(nt_code));
-               return msg;
-       }
+       /*
+        * This should not really happen, we should have all error codes
+        * available. We have a problem that this might get wrongly
+        * overwritten by later calls in the same DEBUG statement.
+        */
 
-       result = talloc_asprintf(talloc_tos(), "NT code 0x%08x",
-                                NT_STATUS_V(nt_code));
-       SMB_ASSERT(result != NULL);
-       return result;
+       snprintf(msg, sizeof(msg), "NT code 0x%08x", NT_STATUS_V(nt_code));
+       return msg;
 }
 
 /************************************************************************
index 3bfa4b1cdc673abc47b55be782ad1ab8c7b03cd8..ccb882d7618b2916c1e9eeff9ac2cf406f4ebb40 100644 (file)
@@ -5,7 +5,7 @@ bld.SAMBA_LIBRARY('errors',
                   public_headers='error.h ntstatus.h doserr.h werror.h hresult.h',
                   header_path='core',
                   source='doserr.c errormap.c nterr.c errmap_unix.c hresult.c',
-                  public_deps='talloc samba-util',
+                  public_deps='talloc samba-debug',
                   private_library=True
                   )