From 344eb08ee4e444c1fc1beac26e50c6a85b942885 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Wed, 4 May 2011 15:30:01 +1000 Subject: nterr: Add mem_ctx for return string from get_nt_error_c_code() It is clearer to avoid the implicit return on talloc_tos() Andrew Bartlett --- source3/include/proto.h | 1 - source3/libsmb/nterr.c | 8 ++++---- source3/torture/torture.c | 6 +++--- 3 files changed, 7 insertions(+), 8 deletions(-) (limited to 'source3') diff --git a/source3/include/proto.h b/source3/include/proto.h index 2305a7ac68..a6e9cf9b5d 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -1976,7 +1976,6 @@ bool get_dc_name(const char *domain, const char *nt_errstr(NTSTATUS nt_code); const char *get_friendly_nt_error_msg(NTSTATUS nt_code); -const char *get_nt_error_c_code(NTSTATUS nt_code); NTSTATUS nt_status_string_to_code(const char *nt_status_str); NTSTATUS nt_status_squash(NTSTATUS nt_status); diff --git a/source3/libsmb/nterr.c b/source3/libsmb/nterr.c index e48f221be0..0201aa2ddc 100644 --- a/source3/libsmb/nterr.c +++ b/source3/libsmb/nterr.c @@ -740,7 +740,7 @@ const char *get_friendly_nt_error_msg(NTSTATUS nt_code) Returns an NT_STATUS constant as a string for inclusion in autogen C code. *****************************************************************************/ -const char *get_nt_error_c_code(NTSTATUS nt_code) +const char *get_nt_error_c_code(TALLOC_CTX *mem_ctx, NTSTATUS nt_code) { char *result; int idx = 0; @@ -748,14 +748,14 @@ const char *get_nt_error_c_code(NTSTATUS nt_code) while (nt_errs[idx].nt_errstr != NULL) { if (NT_STATUS_V(nt_errs[idx].nt_errcode) == NT_STATUS_V(nt_code)) { - return nt_errs[idx].nt_errstr; + result = talloc_strdup(mem_ctx, nt_errs[idx].nt_errstr); + return result; } idx++; } - result = talloc_asprintf(talloc_tos(), "NT_STATUS(0x%08x)", + result = talloc_asprintf(mem_ctx, "NT_STATUS(0x%08x)", NT_STATUS_V(nt_code)); - SMB_ASSERT(result); return result; } diff --git a/source3/torture/torture.c b/source3/torture/torture.c index b0e5cf8a02..fe9a5cb093 100644 --- a/source3/torture/torture.c +++ b/source3/torture/torture.c @@ -5910,14 +5910,14 @@ static bool run_error_map_extract(int dummy) { if (NT_STATUS_V(nt_status) != error) { printf("/*\t{ This NT error code was 'sqashed'\n\t from %s to %s \n\t during the session setup }\n*/\n", - get_nt_error_c_code(NT_STATUS(error)), - get_nt_error_c_code(nt_status)); + get_nt_error_c_code(talloc_tos(), NT_STATUS(error)), + get_nt_error_c_code(talloc_tos(), nt_status)); } printf("\t{%s,\t%s,\t%s},\n", smb_dos_err_class(errclass), smb_dos_err_name(errclass, errnum), - get_nt_error_c_code(NT_STATUS(error))); + get_nt_error_c_code(talloc_tos(), NT_STATUS(error))); } return True; } -- cgit