1
0
mirror of https://github.com/samba-team/samba.git synced 2025-02-24 13:57:43 +03:00

libndr: Use TALLOC_FREE instead of talloc_free

All the existing calls are right before returns, so they don't really
matter. But you never know when the code will change, and any compiler
will wipe the NULL assignment.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Noel Power <noel.power@suse.com>
This commit is contained in:
Volker Lendecke 2024-09-12 16:18:57 +02:00
parent e9538317d8
commit 9d4a7a448e
9 changed files with 40 additions and 40 deletions

View File

@ -478,7 +478,7 @@ enum ndr_compression_alg {
enum ndr_err_code _status; \ enum ndr_err_code _status; \
_status = call; \ _status = call; \
if (unlikely(!NDR_ERR_CODE_IS_SUCCESS(_status))) { \ if (unlikely(!NDR_ERR_CODE_IS_SUCCESS(_status))) { \
talloc_free(ndr); \ TALLOC_FREE(ndr); \
return _status; \ return _status; \
} \ } \
} while (0) } while (0)

View File

@ -238,7 +238,7 @@ _PUBLIC_ struct ndr_push *ndr_push_init_ctx(TALLOC_CTX *mem_ctx)
ndr->alloc_size = NDR_BASE_MARSHALL_SIZE; ndr->alloc_size = NDR_BASE_MARSHALL_SIZE;
ndr->data = talloc_array(ndr, uint8_t, ndr->alloc_size); ndr->data = talloc_array(ndr, uint8_t, ndr->alloc_size);
if (!ndr->data) { if (!ndr->data) {
talloc_free(ndr); TALLOC_FREE(ndr);
return NULL; return NULL;
} }
@ -425,7 +425,7 @@ _PUBLIC_ void ndr_print_debugc(int dbgc_class, ndr_print_fn_t fn, const char *na
#endif #endif
fn(ndr, name, ptr); fn(ndr, name, ptr);
talloc_free(ndr); TALLOC_FREE(ndr);
} }
/* /*
@ -461,7 +461,7 @@ _PUBLIC_ bool ndr_print_debug(int level,
ret = true; ret = true;
fail: fail:
talloc_free(ndr); TALLOC_FREE(ndr);
return ret; return ret;
} }
@ -487,7 +487,7 @@ _PUBLIC_ void ndr_print_union_debug(ndr_print_fn_t fn, const char *name, uint32_
ndr_print_set_switch_value(ndr, ptr, level); ndr_print_set_switch_value(ndr, ptr, level);
fn(ndr, name, ptr); fn(ndr, name, ptr);
talloc_free(ndr); TALLOC_FREE(ndr);
} }
/* /*
@ -511,7 +511,7 @@ _PUBLIC_ void ndr_print_function_debug(ndr_print_function_t fn, const char *name
#endif #endif
fn(ndr, name, flags, ptr); fn(ndr, name, flags, ptr);
talloc_free(ndr); TALLOC_FREE(ndr);
} }
/* /*
@ -535,7 +535,7 @@ _PUBLIC_ char *ndr_print_struct_string(TALLOC_CTX *mem_ctx, ndr_print_fn_t fn, c
fn(ndr, name, ptr); fn(ndr, name, ptr);
ret = talloc_steal(mem_ctx, (char *)ndr->private_data); ret = talloc_steal(mem_ctx, (char *)ndr->private_data);
failed: failed:
talloc_free(ndr); TALLOC_FREE(ndr);
return ret; return ret;
} }
@ -560,7 +560,7 @@ _PUBLIC_ char *ndr_print_union_string(TALLOC_CTX *mem_ctx, ndr_print_fn_t fn, co
fn(ndr, name, ptr); fn(ndr, name, ptr);
ret = talloc_steal(mem_ctx, (char *)ndr->private_data); ret = talloc_steal(mem_ctx, (char *)ndr->private_data);
failed: failed:
talloc_free(ndr); TALLOC_FREE(ndr);
return ret; return ret;
} }
@ -586,7 +586,7 @@ _PUBLIC_ char *ndr_print_function_string(TALLOC_CTX *mem_ctx,
fn(ndr, name, flags, ptr); fn(ndr, name, flags, ptr);
ret = talloc_steal(mem_ctx, (char *)ndr->private_data); ret = talloc_steal(mem_ctx, (char *)ndr->private_data);
failed: failed:
talloc_free(ndr); TALLOC_FREE(ndr);
return ret; return ret;
} }
@ -901,7 +901,7 @@ _PUBLIC_ enum ndr_err_code ndr_push_subcontext_start(struct ndr_push *ndr,
status = ndr_push_zero(subndr, size_is); status = ndr_push_zero(subndr, size_is);
if (!NDR_ERR_CODE_IS_SUCCESS(status)) { if (!NDR_ERR_CODE_IS_SUCCESS(status)) {
talloc_free(subndr); TALLOC_FREE(subndr);
return status; return status;
} }
subndr->offset = 0; subndr->offset = 0;
@ -1337,7 +1337,7 @@ _PUBLIC_ enum ndr_err_code ndr_pull_struct_blob(const DATA_BLOB *blob, TALLOC_CT
ndr = ndr_pull_init_blob(blob, mem_ctx); ndr = ndr_pull_init_blob(blob, mem_ctx);
NDR_ERR_HAVE_NO_MEMORY(ndr); NDR_ERR_HAVE_NO_MEMORY(ndr);
NDR_CHECK_FREE(fn(ndr, NDR_SCALARS|NDR_BUFFERS, p)); NDR_CHECK_FREE(fn(ndr, NDR_SCALARS|NDR_BUFFERS, p));
talloc_free(ndr); TALLOC_FREE(ndr);
return NDR_ERR_SUCCESS; return NDR_ERR_SUCCESS;
} }
@ -1362,10 +1362,10 @@ _PUBLIC_ enum ndr_err_code ndr_pull_struct_blob_all(const DATA_BLOB *blob, TALLO
ret = ndr_pull_error(ndr, NDR_ERR_UNREAD_BYTES, ret = ndr_pull_error(ndr, NDR_ERR_UNREAD_BYTES,
"not all bytes consumed ofs[%"PRIu32"] size[%"PRIu32"]", "not all bytes consumed ofs[%"PRIu32"] size[%"PRIu32"]",
highest_ofs, ndr->data_size); highest_ofs, ndr->data_size);
talloc_free(ndr); TALLOC_FREE(ndr);
return ret; return ret;
} }
talloc_free(ndr); TALLOC_FREE(ndr);
return NDR_ERR_SUCCESS; return NDR_ERR_SUCCESS;
} }
@ -1446,7 +1446,7 @@ _PUBLIC_ enum ndr_err_code ndr_pull_union_blob(const DATA_BLOB *blob, TALLOC_CTX
NDR_ERR_HAVE_NO_MEMORY(ndr); NDR_ERR_HAVE_NO_MEMORY(ndr);
NDR_CHECK_FREE(ndr_pull_set_switch_value(ndr, p, level)); NDR_CHECK_FREE(ndr_pull_set_switch_value(ndr, p, level));
NDR_CHECK_FREE(fn(ndr, NDR_SCALARS|NDR_BUFFERS, p)); NDR_CHECK_FREE(fn(ndr, NDR_SCALARS|NDR_BUFFERS, p));
talloc_free(ndr); TALLOC_FREE(ndr);
return NDR_ERR_SUCCESS; return NDR_ERR_SUCCESS;
} }
@ -1474,10 +1474,10 @@ _PUBLIC_ enum ndr_err_code ndr_pull_union_blob_all(const DATA_BLOB *blob, TALLOC
ret = ndr_pull_error(ndr, NDR_ERR_UNREAD_BYTES, ret = ndr_pull_error(ndr, NDR_ERR_UNREAD_BYTES,
"not all bytes consumed ofs[%"PRIu32"] size[%"PRIu32"]", "not all bytes consumed ofs[%"PRIu32"] size[%"PRIu32"]",
highest_ofs, ndr->data_size); highest_ofs, ndr->data_size);
talloc_free(ndr); TALLOC_FREE(ndr);
return ret; return ret;
} }
talloc_free(ndr); TALLOC_FREE(ndr);
return NDR_ERR_SUCCESS; return NDR_ERR_SUCCESS;
} }
@ -1494,7 +1494,7 @@ _PUBLIC_ enum ndr_err_code ndr_push_struct_blob(DATA_BLOB *blob, TALLOC_CTX *mem
*blob = ndr_push_blob(ndr); *blob = ndr_push_blob(ndr);
talloc_steal(mem_ctx, blob->data); talloc_steal(mem_ctx, blob->data);
talloc_free(ndr); TALLOC_FREE(ndr);
return NDR_ERR_SUCCESS; return NDR_ERR_SUCCESS;
} }
@ -1543,7 +1543,7 @@ _PUBLIC_ enum ndr_err_code ndr_push_union_blob(DATA_BLOB *blob, TALLOC_CTX *mem_
*blob = ndr_push_blob(ndr); *blob = ndr_push_blob(ndr);
talloc_steal(mem_ctx, blob->data); talloc_steal(mem_ctx, blob->data);
talloc_free(ndr); TALLOC_FREE(ndr);
return NDR_ERR_SUCCESS; return NDR_ERR_SUCCESS;
} }
@ -1570,11 +1570,11 @@ _PUBLIC_ size_t ndr_size_struct(const void *p, libndr_flags flags, ndr_push_flag
ndr->flags |= flags | LIBNDR_FLAG_NO_NDR_SIZE; ndr->flags |= flags | LIBNDR_FLAG_NO_NDR_SIZE;
status = push(ndr, NDR_SCALARS|NDR_BUFFERS, discard_const(p)); status = push(ndr, NDR_SCALARS|NDR_BUFFERS, discard_const(p));
if (!NDR_ERR_CODE_IS_SUCCESS(status)) { if (!NDR_ERR_CODE_IS_SUCCESS(status)) {
talloc_free(ndr); TALLOC_FREE(ndr);
return 0; return 0;
} }
ret = ndr->offset; ret = ndr->offset;
talloc_free(ndr); TALLOC_FREE(ndr);
return ret; return ret;
} }
@ -1601,16 +1601,16 @@ _PUBLIC_ size_t ndr_size_union(const void *p, libndr_flags flags, uint32_t level
status = ndr_push_set_switch_value(ndr, p, level); status = ndr_push_set_switch_value(ndr, p, level);
if (!NDR_ERR_CODE_IS_SUCCESS(status)) { if (!NDR_ERR_CODE_IS_SUCCESS(status)) {
talloc_free(ndr); TALLOC_FREE(ndr);
return 0; return 0;
} }
status = push(ndr, NDR_SCALARS|NDR_BUFFERS, p); status = push(ndr, NDR_SCALARS|NDR_BUFFERS, p);
if (!NDR_ERR_CODE_IS_SUCCESS(status)) { if (!NDR_ERR_CODE_IS_SUCCESS(status)) {
talloc_free(ndr); TALLOC_FREE(ndr);
return 0; return 0;
} }
ret = ndr->offset; ret = ndr->offset;
talloc_free(ndr); TALLOC_FREE(ndr);
return ret; return ret;
} }

View File

@ -36,7 +36,7 @@ _PUBLIC_ void ndr_print_cf_time(struct ndr_print *ndr, const char *name, const s
s = talloc_asprintf(ndr, "%02d:%02d:%02d", hour, minute, seconds); s = talloc_asprintf(ndr, "%02d:%02d:%02d", hour, minute, seconds);
if (s == NULL) { return; } if (s == NULL) { return; }
ndr_print_string(ndr, "time", s); ndr_print_string(ndr, "time", s);
talloc_free(s); TALLOC_FREE(s);
} }
_PUBLIC_ void ndr_print_cf_date(struct ndr_print *ndr, const char *name, const struct cf_date *r) _PUBLIC_ void ndr_print_cf_date(struct ndr_print *ndr, const char *name, const struct cf_date *r)
@ -52,7 +52,7 @@ _PUBLIC_ void ndr_print_cf_date(struct ndr_print *ndr, const char *name, const s
s = talloc_asprintf(ndr, "%02"PRIu8"/%02"PRIu8"/%04"PRIu16, day, month, year); s = talloc_asprintf(ndr, "%02"PRIu8"/%02"PRIu8"/%04"PRIu16, day, month, year);
if (s == NULL) { return; } if (s == NULL) { return; }
ndr_print_string(ndr, "date", s); ndr_print_string(ndr, "date", s);
talloc_free(s); TALLOC_FREE(s);
} }
uint32_t ndr_count_cfdata(const struct cab_file *r) uint32_t ndr_count_cfdata(const struct cab_file *r)

View File

@ -48,7 +48,7 @@ static voidpf ndr_zlib_alloc(voidpf opaque, uInt items, uInt size)
static void ndr_zlib_free(voidpf opaque, voidpf address) static void ndr_zlib_free(voidpf opaque, voidpf address)
{ {
talloc_free(address); TALLOC_FREE(address);
} }
static enum ndr_err_code ndr_pull_compression_mszip_cab_chunk(struct ndr_pull *ndrpull, static enum ndr_err_code ndr_pull_compression_mszip_cab_chunk(struct ndr_pull *ndrpull,
@ -974,7 +974,7 @@ enum ndr_err_code ndr_push_compression_end(struct ndr_push *subndr,
compression_alg); compression_alg);
} }
talloc_free(uncomndr); TALLOC_FREE(uncomndr);
return NDR_ERR_SUCCESS; return NDR_ERR_SUCCESS;
} }

View File

@ -142,8 +142,8 @@ _PUBLIC_ void ndr_print_drsuapi_MSPrefixMap_Entry(struct ndr_print *ndr, const c
ndr->depth++; ndr->depth++;
ndr->print(ndr, "%-25s: 0x%s (%s)", "binary_oid", hex_str, partial_oid); ndr->print(ndr, "%-25s: 0x%s (%s)", "binary_oid", hex_str, partial_oid);
ndr->depth--; ndr->depth--;
talloc_free(hex_str); TALLOC_FREE(hex_str);
talloc_free(partial_oid); TALLOC_FREE(partial_oid);
} }
ndr->depth--; ndr->depth--;
ndr->flags = _flags_save_STRUCT; ndr->flags = _flags_save_STRUCT;

View File

@ -81,8 +81,8 @@ _PUBLIC_ void ndr_print_drsuapi_DsReplicaOID(struct ndr_print *ndr, const char *
ndr->depth++; ndr->depth++;
ndr->print(ndr, "%-25s: 0x%s (%s)", "binary_oid", hex_str, partial_oid); ndr->print(ndr, "%-25s: 0x%s (%s)", "binary_oid", hex_str, partial_oid);
ndr->depth--; ndr->depth--;
talloc_free(hex_str); TALLOC_FREE(hex_str);
talloc_free(partial_oid); TALLOC_FREE(partial_oid);
} }
ndr->depth--; ndr->depth--;
} }
@ -125,7 +125,7 @@ static void _print_drsuapi_DsAttributeValue_str(struct ndr_print *ndr, const cha
} else { } else {
char *str = (char *)p; char *str = (char *)p;
ndr_print_string(ndr, "string", str); ndr_print_string(ndr, "string", str);
talloc_free(str); TALLOC_FREE(str);
} }
ndr->depth--; ndr->depth--;
} }
@ -223,7 +223,7 @@ enum ndr_err_code ndr_push_drsuapi_DsGetNCChangesMSZIPCtr1(struct ndr_push *ndr,
NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed)); NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed));
} }
compressed_length = _ndr_ts->offset; compressed_length = _ndr_ts->offset;
talloc_free(_ndr_ts); TALLOC_FREE(_ndr_ts);
} }
} }
NDR_CHECK(ndr_push_align(ndr, 4)); NDR_CHECK(ndr_push_align(ndr, 4));
@ -268,7 +268,7 @@ enum ndr_err_code ndr_push_drsuapi_DsGetNCChangesMSZIPCtr6(struct ndr_push *ndr,
NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed)); NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed));
} }
compressed_length = _ndr_ts->offset; compressed_length = _ndr_ts->offset;
talloc_free(_ndr_ts); TALLOC_FREE(_ndr_ts);
} }
} }
NDR_CHECK(ndr_push_align(ndr, 4)); NDR_CHECK(ndr_push_align(ndr, 4));
@ -313,7 +313,7 @@ enum ndr_err_code ndr_push_drsuapi_DsGetNCChangesWIN2K3_LZ77_DIRECT2Ctr1(struct
NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed)); NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed));
} }
compressed_length = _ndr_ts->offset; compressed_length = _ndr_ts->offset;
talloc_free(_ndr_ts); TALLOC_FREE(_ndr_ts);
} }
} }
NDR_CHECK(ndr_push_align(ndr, 4)); NDR_CHECK(ndr_push_align(ndr, 4));
@ -358,7 +358,7 @@ enum ndr_err_code ndr_push_drsuapi_DsGetNCChangesWIN2K3_LZ77_DIRECT2Ctr6(struct
NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed)); NDR_CHECK(ndr_push_compression_end(_ndr_ts, _ndr_ts_compressed));
} }
compressed_length = _ndr_ts->offset; compressed_length = _ndr_ts->offset;
talloc_free(_ndr_ts); TALLOC_FREE(_ndr_ts);
} }
} }
NDR_CHECK(ndr_push_align(ndr, 4)); NDR_CHECK(ndr_push_align(ndr, 4));

View File

@ -336,7 +336,7 @@ enum ndr_err_code ndr_pull_dom_sid28(struct ndr_pull *ndr, ndr_flags_type ndr_fl
status = ndr_pull_advance(ndr, 28); status = ndr_pull_advance(ndr, 28);
if (!NDR_ERR_CODE_IS_SUCCESS(status)) { if (!NDR_ERR_CODE_IS_SUCCESS(status)) {
talloc_free(subndr); TALLOC_FREE(subndr);
return status; return status;
} }
@ -348,7 +348,7 @@ enum ndr_err_code ndr_pull_dom_sid28(struct ndr_pull *ndr, ndr_flags_type ndr_fl
ZERO_STRUCT(sid->sub_auths); ZERO_STRUCT(sid->sub_auths);
} }
talloc_free(subndr); TALLOC_FREE(subndr);
return NDR_ERR_SUCCESS; return NDR_ERR_SUCCESS;
} }

View File

@ -1579,7 +1579,7 @@ _PUBLIC_ void ndr_print_spoolss_Time(struct ndr_print *ndr, const char *name, co
ndr->depth++; ndr->depth++;
ndr_print_string(ndr, "", str); ndr_print_string(ndr, "", str);
ndr->depth--; ndr->depth--;
talloc_free(str); TALLOC_FREE(str);
} }
_PUBLIC_ libndr_flags ndr_spoolss_PrinterEnumValues_align(enum winreg_Type type) _PUBLIC_ libndr_flags ndr_spoolss_PrinterEnumValues_align(enum winreg_Type type)

View File

@ -419,7 +419,7 @@ _PUBLIC_ enum ndr_err_code ndr_push_string(struct ndr_push *ndr, ndr_flags_type
} }
out: out:
talloc_free(dest_to_free); TALLOC_FREE(dest_to_free);
return ndr_err; return ndr_err;
} }