summaryrefslogtreecommitdiff
path: root/source3/lib/util_str.c
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2004-12-07 18:25:53 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 10:53:32 -0500
commitacf9d61421faa6c0055d57fdee7db300dc5431aa (patch)
tree5482afecfe9b4a68b9a1f18d541a3109f8143ab7 /source3/lib/util_str.c
parent3bd3be97dc8a581c0502410453091c195e322766 (diff)
downloadsamba-acf9d61421faa6c0055d57fdee7db300dc5431aa.tar.gz
samba-acf9d61421faa6c0055d57fdee7db300dc5431aa.tar.bz2
samba-acf9d61421faa6c0055d57fdee7db300dc5431aa.zip
r4088: Get medieval on our ass about malloc.... :-). Take control of all our allocation
functions so we can funnel through some well known functions. Should help greatly with malloc checking. HEAD patch to follow. Jeremy. (This used to be commit 620f2e608f70ba92f032720c031283d295c5c06a)
Diffstat (limited to 'source3/lib/util_str.c')
-rw-r--r--source3/lib/util_str.c38
1 files changed, 19 insertions, 19 deletions
diff --git a/source3/lib/util_str.c b/source3/lib/util_str.c
index a758aece4c..c6b6570f5c 100644
--- a/source3/lib/util_str.c
+++ b/source3/lib/util_str.c
@@ -134,7 +134,7 @@ char **toktocliplist(int *ctok, const char *sep)
*ctok=ictok;
s=(char *)last_ptr;
- if (!(ret=iret=malloc((ictok+1)*sizeof(char *))))
+ if (!(ret=iret=SMB_MALLOC_ARRAY(char *,ictok+1)))
return NULL;
while(ictok--) {
@@ -815,7 +815,7 @@ void hex_encode(const unsigned char *buff_in, size_t len, char **out_hex_buffer)
int i;
char *hex_buffer;
- *out_hex_buffer = smb_xmalloc((len*2)+1);
+ *out_hex_buffer = SMB_XMALLOC_ARRAY(char, (len*2)+1);
hex_buffer = *out_hex_buffer;
for (i = 0; i < len; i++)
@@ -863,7 +863,7 @@ static BOOL string_init(char **dest,const char *src)
if (l == 0) {
if (!null_string) {
- if((null_string = (char *)malloc(1)) == NULL) {
+ if((null_string = (char *)SMB_MALLOC(1)) == NULL) {
DEBUG(0,("string_init: malloc fail for null_string.\n"));
return False;
}
@@ -871,7 +871,7 @@ static BOOL string_init(char **dest,const char *src)
}
*dest = null_string;
} else {
- (*dest) = strdup(src);
+ (*dest) = SMB_STRDUP(src);
if ((*dest) == NULL) {
DEBUG(0,("Out of memory in string_init\n"));
return False;
@@ -990,7 +990,7 @@ char *realloc_string_sub(char *string, const char *pattern, const char *insert)
s = string;
- in = strdup(insert);
+ in = SMB_STRDUP(insert);
if (!in) {
DEBUG(0, ("realloc_string_sub: out of memory!\n"));
return NULL;
@@ -1019,7 +1019,7 @@ char *realloc_string_sub(char *string, const char *pattern, const char *insert)
while ((p = strstr_m(s,pattern))) {
if (ld > 0) {
int offset = PTR_DIFF(s,string);
- char *t = Realloc(string, ls + ld + 1);
+ char *t = SMB_REALLOC(string, ls + ld + 1);
if (!t) {
DEBUG(0, ("realloc_string_sub: out of memory!\n"));
SAFE_FREE(in);
@@ -1110,7 +1110,7 @@ static smb_ucs2_t *all_string_sub_w(const smb_ucs2_t *s, const smb_ucs2_t *patte
}
}
- r = rp = (smb_ucs2_t *)malloc((lt + 1)*(sizeof(smb_ucs2_t)));
+ r = rp = SMB_MALLOC_ARRAY(smb_ucs2_t, lt + 1);
if (!r) {
DEBUG(0, ("all_string_sub_w: out of memory!\n"));
return NULL;
@@ -1478,7 +1478,7 @@ char *binary_string(char *buf, int len)
char *s;
int i, j;
const char *hex = "0123456789ABCDEF";
- s = malloc(len * 3 + 1);
+ s = SMB_MALLOC(len * 3 + 1);
if (!s)
return NULL;
for (j=i=0;i<len;i++) {
@@ -1533,7 +1533,7 @@ int fstr_sprintf(fstring s, const char *fmt, ...)
char *ret;
n = strnlen(s, n);
- ret = malloc(n+1);
+ ret = SMB_MALLOC(n+1);
if (!ret)
return NULL;
memcpy(ret, s, n);
@@ -1573,7 +1573,7 @@ char **str_list_make(const char *string, const char *sep)
if (!string || !*string)
return NULL;
- s = strdup(string);
+ s = SMB_STRDUP(string);
if (!s) {
DEBUG(0,("str_list_make: Unable to allocate memory"));
return NULL;
@@ -1587,7 +1587,7 @@ char **str_list_make(const char *string, const char *sep)
while (next_token(&str, tok, sep, sizeof(tok))) {
if (num == lsize) {
lsize += S_LIST_ABS;
- rlist = (char **)Realloc(list, ((sizeof(char **)) * (lsize +1)));
+ rlist = SMB_REALLOC_ARRAY(list, char *, lsize +1);
if (!rlist) {
DEBUG(0,("str_list_make: Unable to allocate memory"));
str_list_free(&list);
@@ -1598,7 +1598,7 @@ char **str_list_make(const char *string, const char *sep)
memset (&list[num], 0, ((sizeof(char**)) * (S_LIST_ABS +1)));
}
- list[num] = strdup(tok);
+ list[num] = SMB_STRDUP(tok);
if (!list[num]) {
DEBUG(0,("str_list_make: Unable to allocate memory"));
str_list_free(&list);
@@ -1628,7 +1628,7 @@ BOOL str_list_copy(char ***dest, const char **src)
while (src[num]) {
if (num == lsize) {
lsize += S_LIST_ABS;
- rlist = (char **)Realloc(list, ((sizeof(char **)) * (lsize +1)));
+ rlist = SMB_REALLOC_ARRAY(list, char *, lsize +1);
if (!rlist) {
DEBUG(0,("str_list_copy: Unable to re-allocate memory"));
str_list_free(&list);
@@ -1638,7 +1638,7 @@ BOOL str_list_copy(char ***dest, const char **src)
memset (&list[num], 0, ((sizeof(char **)) * (S_LIST_ABS +1)));
}
- list[num] = strdup(src[num]);
+ list[num] = SMB_STRDUP(src[num]);
if (!list[num]) {
DEBUG(0,("str_list_copy: Unable to allocate memory"));
str_list_free(&list);
@@ -1740,7 +1740,7 @@ BOOL str_list_substitute(char **list, const char *pattern, const char *insert)
t = *list;
d = p -t;
if (ld) {
- t = (char *) malloc(ls +ld +1);
+ t = (char *) SMB_MALLOC(ls +ld +1);
if (!t) {
DEBUG(0,("str_list_substitute: Unable to allocate memory"));
return False;
@@ -1863,7 +1863,7 @@ int ipstr_list_parse(const char* ipstr_list, struct ip_service **ip_list)
return 0;
count = count_chars(ipstr_list, IPSTR_LIST_CHAR) + 1;
- if ( (*ip_list = (struct ip_service*)malloc(count * sizeof(struct ip_service))) == NULL ) {
+ if ( (*ip_list = SMB_MALLOC_ARRAY(struct ip_service, count)) == NULL ) {
DEBUG(0,("ipstr_list_parse: malloc failed for %lu entries\n", (unsigned long)count));
return 0;
}
@@ -2011,7 +2011,7 @@ char * base64_encode_data_blob(DATA_BLOB data)
size_t out_cnt = 0;
size_t len = data.length;
size_t output_len = data.length * 2;
- char *result = malloc(output_len); /* get us plenty of space */
+ char *result = SMB_MALLOC(output_len); /* get us plenty of space */
while (len-- && out_cnt < (data.length * 2) - 5) {
int c = (unsigned char) *(data.data++);
@@ -2072,11 +2072,11 @@ void string_append(char **left, const char *right)
int new_len = strlen(right) + 1;
if (*left == NULL) {
- *left = malloc(new_len);
+ *left = SMB_MALLOC(new_len);
*left[0] = '\0';
} else {
new_len += strlen(*left);
- *left = Realloc(*left, new_len);
+ *left = SMB_REALLOC(*left, new_len);
}
if (*left == NULL)