From a38e5e6850220fc1a0afa5097359c05458e1ae41 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sat, 22 Mar 2003 13:06:52 +0000 Subject: Small clenaup patches: - safe_string.h - don't assume that __FUNCTION__ is available - process.c - use new workaround from safe_string.h for the same - util.c - Show how many bytes we smb_panic()ed trying to smb_xmalloc() - gencache.c - Keep valgrind quiet by always null terminating. - clistr.c - Add copyright - srvstr.h - move srvstr_push into a .c file again, as a real function. - srvstr.c - revive, with 'safe' checked srvstr_push - loadparm.c - set a default for the display charset. Andrew Bartlett (This used to be commit a7eba37aadeb0b04cb1bd89deddb58be8aba825c) --- source3/lib/gencache.c | 12 ++++++------ source3/lib/util.c | 4 +++- 2 files changed, 9 insertions(+), 7 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/gencache.c b/source3/lib/gencache.c index 5c8ad1339b2..eb0e0cd808f 100644 --- a/source3/lib/gencache.c +++ b/source3/lib/gencache.c @@ -115,9 +115,9 @@ BOOL gencache_set(const char *keystr, const char *value, time_t timeout) asprintf(&valstr, CACHE_DATA_FMT, (int)timeout, value); keybuf.dptr = strdup(keystr); - keybuf.dsize = strlen(keystr); + keybuf.dsize = strlen(keystr)+1; databuf.dptr = strdup(valstr); - databuf.dsize = strlen(valstr); + databuf.dsize = strlen(valstr)+1; DEBUG(10, ("Adding cache entry with key = %s; value = %s and timeout \ = %s (%d seconds %s)\n", keybuf.dptr, value, ctime(&timeout), (int)(timeout - time(NULL)), timeout > time(NULL) ? "ahead" : "in the past")); @@ -167,9 +167,9 @@ BOOL gencache_set_only(const char *keystr, const char *valstr, time_t timeout) asprintf(&datastr, CACHE_DATA_FMT, (int)timeout, valstr); keybuf.dptr = strdup(keystr); - keybuf.dsize = strlen(keystr); + keybuf.dsize = strlen(keystr)+1; databuf.dptr = strdup(datastr); - databuf.dsize = strlen(datastr); + databuf.dsize = strlen(datastr)+1; DEBUGADD(10, ("New value = %s, new timeout = %s (%d seconds %s)", valstr, ctime(&timeout), (int)(timeout - time(NULL)), timeout > time(NULL) ? "ahead" : "in the past")); @@ -206,7 +206,7 @@ BOOL gencache_del(const char *keystr) if (!gencache_init()) return False; keybuf.dptr = strdup(keystr); - keybuf.dsize = strlen(keystr); + keybuf.dsize = strlen(keystr)+1; DEBUG(10, ("Deleting cache entry (key = %s)\n", keystr)); ret = tdb_delete(cache, keybuf); @@ -239,7 +239,7 @@ BOOL gencache_get(const char *keystr, char **valstr, time_t *timeout) return False; keybuf.dptr = strdup(keystr); - keybuf.dsize = strlen(keystr); + keybuf.dsize = strlen(keystr)+1; databuf = tdb_fetch(cache, keybuf); if (databuf.dptr && databuf.dsize > TIMEOUT_LEN) { diff --git a/source3/lib/util.c b/source3/lib/util.c index 42163103359..4f564b332a0 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -2089,8 +2089,10 @@ void *smb_xmalloc(size_t size) void *p; if (size == 0) smb_panic("smb_xmalloc: called with zero size.\n"); - if ((p = malloc(size)) == NULL) + if ((p = malloc(size)) == NULL) { + DEBUG(0, ("smb_xmalloc() failed to allocate %lu bytes\n", (unsigned long)size)); smb_panic("smb_xmalloc: malloc fail.\n"); + } return p; } -- cgit