/* useful macros for creating type checked pointers */
#define talloc(ctx, size) talloc_named_const(ctx, size, __location__)
-#define talloc_realloc(ptr, size) _talloc_realloc(ptr, size, __location__)
+#define talloc_realloc(ctx, ptr, size) _talloc_realloc(ctx, ptr, size, __location__)
#define talloc_p(ctx, type) (type *)talloc_named_const(ctx, sizeof(type), #type)
#define talloc_array_p(ctx, type, count) (type *)talloc_array(ctx, sizeof(type), count, __location__)
-#define talloc_realloc_p(p, type, count) (type *)talloc_realloc_array(p, sizeof(type), count, __location__)
+#define talloc_realloc_p(ctx, p, type, count) (type *)talloc_realloc_array(ctx, p, sizeof(type), count, __location__)
#define talloc_memdup(t, p, size) _talloc_memdup(t, p, size, __location__)
#define talloc_destroy(ctx) talloc_free(ctx)
outbuf = NULL;
convert:
destlen = destlen * 2;
- if (outbuf == NULL) {
- ob = talloc_array_p(ctx, char, destlen);
- } else {
- ob = (char *)talloc_realloc(outbuf, destlen);
- }
+ ob = (char *)talloc_realloc(ctx, outbuf, destlen);
if (!ob) {
DEBUG(0, ("convert_string_talloc: realloc failed!\n"));
talloc_free(outbuf);
destlen = destlen - o_len;
/* +2 for mandetory null termination, UTF8 or UTF16 */
- *dest = (char *)talloc_realloc(ob,destlen+2);
+ *dest = (char *)talloc_realloc(ctx, ob, destlen+2);
if (!*dest) {
DEBUG(0, ("convert_string_talloc: out of memory!\n"));
talloc_free(ob);
/* Add hive to context */
h->num_hives++;
- h->hives = talloc_realloc_p(h->hives, struct registry_hive *, h->num_hives);
+ h->hives = talloc_realloc_p(h, h->hives, struct registry_hive *, h->num_hives);
h->hives[h->num_hives-1] = ret;
return WERR_OK;
int i = 0;
*hives = talloc_p(mem_ctx, char *);
for(i = 0; known_hives[i].name; i++) {
- *hives = talloc_realloc_p(*hives, char *, i+2);
+ *hives = talloc_realloc_p(mem_ctx, *hives, char *, i+2);
(*hives)[i] = talloc_strdup(mem_ctx, known_hives[i].name);
}
(*hives)[i] = NULL;
}
static NTSTATUS ipv4_tcp_recv(struct socket_context *sock, TALLOC_CTX *mem_ctx,
- DATA_BLOB *blob, size_t wantlen, uint32_t flags)
+ DATA_BLOB *blob, size_t wantlen, uint32_t flags)
{
ssize_t gotlen;
void *buf;
}
blob->length = gotlen;
- blob->data = talloc_realloc(buf, gotlen);
+ blob->data = talloc_realloc(mem_ctx, buf, gotlen);
if (!blob->data) {
return NT_STATUS_NO_MEMORY;
}
/*
- A talloc version of realloc
+ A talloc version of realloc. The context argument is only used if
+ ptr is NULL
*/
-void *_talloc_realloc(void *ptr, size_t size, const char *name)
+void *_talloc_realloc(void *context, void *ptr, size_t size, const char *name)
{
struct talloc_chunk *tc;
void *new_ptr;
/* realloc(NULL) is equavalent to malloc() */
if (ptr == NULL) {
- return talloc_named_const(NULL, size, name);
+ return talloc_named_const(context, size, name);
}
tc = talloc_chunk_from_ptr(ptr);
const char *fmt, va_list ap) PRINTF_ATTRIBUTE(2,0);
static char *talloc_vasprintf_append(char *s,
- const char *fmt, va_list ap)
+ const char *fmt, va_list ap)
{
int len, s_len;
va_list ap2;
}
len = vsnprintf(NULL, 0, fmt, ap2);
- s = talloc_realloc(s, s_len + len+1);
+ s = talloc_realloc(NULL, s, s_len + len+1);
if (!s) return NULL;
VA_COPY(ap2, ap);
/*
realloc an array, checking for integer overflow in the array size
*/
-void *talloc_realloc_array(void *ptr, size_t el_size, uint_t count, const char *name)
+void *talloc_realloc_array(void *ctx, void *ptr, size_t el_size, uint_t count, const char *name)
{
if (count == 0 ||
count >= MAX_TALLOC_SIZE/el_size) {
return NULL;
}
- ptr = talloc_realloc(ptr, el_size * count);
+ ptr = talloc_realloc(ctx, ptr, el_size * count);
if (ptr) {
talloc_set_name_const(ptr, name);
}
talloc_free(ptr);
return NULL;
}
- return talloc_realloc(ptr, size);
+ return talloc_realloc(context, ptr, size);
}
{
char *dup_str = talloc_strdup(mem_ctx, str);
- *strings = talloc_realloc(*strings,
- ((*num)+1) * sizeof(**strings));
+ *strings = talloc_realloc_p(mem_ctx,
+ *strings,
+ const char *, ((*num)+1));
if ((*strings == NULL) || (dup_str == NULL))
return False;
for (i = 0; !asn1->has_error &&
0 < asn1_tag_remaining(asn1); i++) {
token->mechTypes =
- talloc_realloc(token->mechTypes, (i + 2) *
+ talloc_realloc(NULL, token->mechTypes, (i + 2) *
sizeof(*token->mechTypes));
asn1_read_OID(asn1, token->mechTypes + i);
if (token->mechTypes[i]) {
file_info *tdl;
/* add file info to the dirlist pool */
- tdl = talloc_realloc(state->dirlist,
+ tdl = talloc_realloc(state,
+ state->dirlist,
state->dirlist_len + sizeof(struct file_info));
if (!tdl) {
file_info *tdl;
/* add file info to the dirlist pool */
- tdl = talloc_realloc(state->dirlist,
+ tdl = talloc_realloc(state,
+ state->dirlist,
state->dirlist_len + sizeof(struct file_info));
if (!tdl) {
while (*s && (next = ldap_parse_filter(mem_ctx, &s))) {
struct ldap_parse_tree **e;
- e = talloc_realloc(ret->u.list.elements,
- sizeof(struct ldap_parse_tree) *
- (ret->u.list.num_elements+1));
+ e = talloc_realloc_p(ret,
+ ret->u.list.elements,
+ struct ldap_parse_tree *,
+ ret->u.list.num_elements+1);
if (!e) {
errno = ENOMEM;
return NULL;
if (chunk_size+1 >= alloc_size) {
char *c2;
alloc_size += 1024;
- c2 = talloc_realloc(chunk, alloc_size);
+ c2 = talloc_realloc(mem_ctx, chunk, alloc_size);
if (!c2) {
errno = ENOMEM;
return NULL;
}
BOOL add_value_to_attrib(TALLOC_CTX *mem_ctx, struct ldap_val *value,
- struct ldap_attribute *attrib)
+ struct ldap_attribute *attrib)
{
- attrib->values = talloc_realloc(attrib->values,
- sizeof(*attrib->values) *
- (attrib->num_values+1));
+ attrib->values = talloc_realloc_p(mem_ctx,
+ attrib->values,
+ DATA_BLOB,
+ attrib->num_values+1);
if (attrib->values == NULL)
return False;
struct ldap_attribute **attribs,
int *num_attribs)
{
- *attribs = talloc_realloc(*attribs,
- sizeof(**attribs) * (*num_attribs+1));
+ *attribs = talloc_realloc_p(mem_ctx,
+ *attribs,
+ struct ldap_attribute,
+ *num_attribs+1);
if (*attribs == NULL)
return False;
}
if (attrib == NULL) {
- r->attributes = talloc_realloc(r->attributes,
- sizeof(*r->attributes) *
- (r->num_attributes+1));
+ r->attributes = talloc_realloc_p(msg->mem_ctx,
+ r->attributes,
+ struct ldap_attribute,
+ r->num_attributes+1);
if (r->attributes == NULL)
return False;
struct ldap_mod **mods,
int *num_mods)
{
- *mods = talloc_realloc(*mods,
- sizeof(**mods) * ((*num_mods)+1));
+ *mods = talloc_realloc_p(mem_ctx, *mods, struct ldap_mod, (*num_mods)+1);
if (*mods == NULL)
return False;
blob2.data = blob->data + ofs;
blob2.length = ea_size - ofs;
- *eas = talloc_realloc(*eas, sizeof(**eas) * (n+1));
+ *eas = talloc_realloc(mem_ctx, *eas, sizeof(**eas) * (n+1));
if (! *eas) return NT_STATUS_NO_MEMORY;
len = ea_pull_struct(&blob2, mem_ctx, &(*eas)[n]);
while (blob->length - ofs >= 24) {
uint_t n = parms->stream_info.out.num_streams;
parms->stream_info.out.streams =
- talloc_realloc(parms->stream_info.out.streams,
- (n+1) * sizeof(parms->stream_info.out.streams[0]));
+ talloc_realloc_p(mem_ctx,
+ parms->stream_info.out.streams,
+ struct stream_struct,
+ n+1);
if (!parms->stream_info.out.streams) {
return NT_STATUS_NO_MEMORY;
}
/* we need to realloc */
req->out.allocated = req->out.size + delta + REQ_OVER_ALLOCATION;
- buf2 = talloc_realloc(req->out.buffer, req->out.allocated);
+ buf2 = talloc_realloc(req, req->out.buffer, req->out.allocated);
if (buf2 == NULL) {
smb_panic("out of memory in req_grow_allocation");
}
max_len = (strlen(str)+2) * MAX_BYTES_PER_CHAR;
- blob->data = talloc_realloc(blob->data, blob->length + max_len);
+ blob->data = talloc_realloc(mem_ctx, blob->data, blob->length + max_len);
if (!blob->data) {
return 0;
}
if (data->has_error) return False;
if (data->length < data->ofs+len) {
uint8_t *newp;
- newp = talloc_realloc(data->data, data->ofs+len);
+ newp = talloc_realloc(NULL, data->data, data->ofs+len);
if (!newp) {
asn1_free(data);
data->has_error = True;
if (size > ndr->alloc_size) {
ndr->alloc_size = size;
}
- ndr->data = talloc_realloc(ndr->data, ndr->alloc_size);
+ ndr->data = talloc_realloc(ndr, ndr->data, ndr->alloc_size);
if (!ndr->data) {
return ndr_push_error(ndr, NDR_ERR_ALLOC, "Failed to push_expand to %u",
ndr->alloc_size);
length = pkt.u.response.stub_and_verifier.length;
if (length > 0) {
- req->payload.data = talloc_realloc(req->payload.data,
+ req->payload.data = talloc_realloc(req,
+ req->payload.data,
req->payload.length + length);
if (!req->payload.data) {
req->status = NT_STATUS_NO_MEMORY;
}
/* initiate another read request, as we only got part of a fragment */
- state->data.data = talloc_realloc(state->data.data, frag_length);
+ state->data.data = talloc_realloc(state, state->data.data, frag_length);
io->readx.in.mincnt = MIN(state->p->srv_max_xmit_frag,
frag_length - state->received);
}
frag_length = dcerpc_get_frag_length(&tcp->recv.data);
- tcp->recv.data.data = talloc_realloc(tcp->recv.data.data,
+ tcp->recv.data.data = talloc_realloc(tcp, tcp->recv.data.data,
frag_length);
if (tcp->recv.data.data == NULL) {
tcp_sock_dead(p, NT_STATUS_NO_MEMORY);
NDR_CHECK(ndr_push_uint16(data_push, heap->offset));
NDR_CHECK(ndr_push_uint16(data_push, 0));
- heap->strings = talloc_realloc(heap->strings,
- sizeof(*heap->strings) *
- (heap->num_strings + 1));
+ heap->strings = talloc_realloc_p(heap->mem_ctx,
+ heap->strings,
+ const char *,
+ heap->num_strings + 1);
if (heap->strings == NULL)
return NT_STATUS_NO_MEMORY;
*/
void ntvfs_set_private(struct smbsrv_tcon *tcon, int depth, void *value)
{
- if (!tcon->ntvfs_private_list) {
- tcon->ntvfs_private_list = talloc_array_p(tcon, void *, depth+1);
- } else {
- tcon->ntvfs_private_list = talloc_realloc_p(tcon->ntvfs_private_list,
- void *, depth+1);
- }
+ tcon->ntvfs_private_list = talloc_realloc_p(tcon,
+ tcon->ntvfs_private_list,
+ void *, depth+1);
tcon->ntvfs_private_list[depth] = value;
}
return NT_STATUS_NO_MEMORY;
}
- dir->names = talloc(dir, 0);
- if (!dir->names) {
- return NT_STATUS_NO_MEMORY;
- }
-
odir = opendir(name->full_name);
if (!odir) {
return pvfs_map_errno(pvfs, errno);
if (dir->count >= allocated) {
allocated = (allocated + 100) * 1.2;
- dir->names = talloc_realloc_p(dir->names, const char *, allocated);
+ dir->names = talloc_realloc_p(dir, dir->names, const char *, allocated);
if (!dir->names) {
closedir(odir);
return NT_STATUS_NO_MEMORY;
struct svfs_dir {
uint_t count;
char *unix_dir;
- struct {
+ struct svfs_dirfile {
char *name;
struct stat st;
} *files;
uint_t allocated = 0;
char *low_mask;
- dir = talloc(mem_ctx, sizeof(struct svfs_dir));
+ dir = talloc_p(mem_ctx, struct svfs_dir);
if (!dir) { return NULL; }
dir->count = 0;
if (dir->count >= allocated) {
allocated = (allocated + 100) * 1.2;
- dir->files = talloc_realloc(dir->files, allocated * sizeof(dir->files[0]));
+ dir->files = talloc_realloc_p(dir, dir->files, struct svfs_dirfile, allocated);
if (!dir->files) {
closedir(odir);
return NULL;
}
call->pkt.u.request.stub_and_verifier.data =
- talloc_realloc(call->pkt.u.request.stub_and_verifier.data, alloc_size);
+ talloc_realloc(call, call->pkt.u.request.stub_and_verifier.data, alloc_size);
if (!call->pkt.u.request.stub_and_verifier.data) {
return dcesrv_fault(call2, DCERPC_FAULT_OTHER);
}
{
NTSTATUS status;
- dce_conn->partial_input.data = talloc_realloc(dce_conn->partial_input.data,
+ dce_conn->partial_input.data = talloc_realloc(dce_conn,
+ dce_conn->partial_input.data,
dce_conn->partial_input.length + data->length);
if (!dce_conn->partial_input.data) {
return NT_STATUS_NO_MEMORY;
struct dcesrv_endpoint *d;
uint32_t total = 0;
- (*eps) = talloc(mem_ctx, 0);
-
+ *eps = NULL;
+
for (d=endpoint_list; d; d=d->next) {
struct dcesrv_if_list *iface;
for (iface=d->interface_list;iface;iface=iface->next) {
- (*eps) = talloc_realloc_p(*eps,
+ (*eps) = talloc_realloc_p(mem_ctx,
+ *eps,
struct dcesrv_ep_iface,
total + 1);
if (!*eps) {
/* over allocate by a small amount */
req->out.allocated = req->out.size + REQ_OVER_ALLOCATION;
- req->out.buffer = talloc_realloc(req->out.buffer, req->out.allocated);
+ req->out.buffer = talloc_realloc(req, req->out.buffer, req->out.allocated);
if (!req->out.buffer) {
smbsrv_terminate_connection(req->smb_conn, "allocation failed");
}
/* we need to realloc */
req->out.allocated = req->out.size + delta + REQ_OVER_ALLOCATION;
- buf2 = talloc_realloc(req->out.buffer, req->out.allocated);
+ buf2 = talloc_realloc(req, req->out.buffer, req->out.allocated);
if (buf2 == NULL) {
smb_panic("out of memory in req_grow_allocation");
}
if (new_size <= trans->out.data.length) {
return;
}
- trans->out.data.data = talloc_realloc(trans->out.data.data, new_size);
+ trans->out.data.data = talloc_realloc(req, trans->out.data.data, new_size);
}
if (call->paramdesc != NULL)
len = strlen(call->paramdesc);
- call->paramdesc = talloc_realloc(call->paramdesc,
+ call->paramdesc = talloc_realloc(call->mem_ctx,
+ call->paramdesc,
len+2);
call->paramdesc[len] = desc;
call->paramdesc[len+1] = '\0';
data->count++;
- data->list = talloc_realloc(data->list,
- data->count * (sizeof(data->list[0])));
+ data->list = talloc_realloc_p(data->mem_ctx,
+ data->list,
+ union smb_search_data,
+ data->count);
data->list[data->count-1] = *file;