summaryrefslogtreecommitdiff
path: root/source3/param
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2000-01-05 06:36:36 +0000
committerAndrew Tridgell <tridge@samba.org>2000-01-05 06:36:36 +0000
commit5e9f5591873fc5c5b5c8dbb0e29a080b8afe9966 (patch)
tree1760a4d063f1b5adf53761dce6ea93d028e45201 /source3/param
parent1f438ffb7ea20673dcd9975528769a0321236a24 (diff)
downloadsamba-5e9f5591873fc5c5b5c8dbb0e29a080b8afe9966.tar.gz
samba-5e9f5591873fc5c5b5c8dbb0e29a080b8afe9966.tar.bz2
samba-5e9f5591873fc5c5b5c8dbb0e29a080b8afe9966.zip
implemented talloc() as described on samba-technical. This fixes the
lp_string() bug properly. we still need to add lp_talloc_free() calls in all the main event loops, I've only put it in smbd and nmbd thus far. (This used to be commit aa7f81552540f5dca2c146f5edd805611d5b390f)
Diffstat (limited to 'source3/param')
-rw-r--r--source3/param/loadparm.c66
1 files changed, 27 insertions, 39 deletions
diff --git a/source3/param/loadparm.c b/source3/param/loadparm.c
index 6d82554130..b76af54609 100644
--- a/source3/param/loadparm.c
+++ b/source3/param/loadparm.c
@@ -1092,55 +1092,43 @@ static void init_locals(void)
#define NUMBER_OF_STATIC_STRING_BUFS 20
+static TALLOC_CTX *lp_talloc;
+
/******************************************************************* a
-convenience routine to grab string parameters into a rotating buffer,
+free up temporary memory - called from the main loop
+********************************************************************/
+void lp_talloc_free(void)
+{
+ if (!lp_talloc) return;
+ talloc_destroy(lp_talloc);
+ lp_talloc = NULL;
+}
+
+/*******************************************************************
+convenience routine to grab string parameters into temporary memory
and run standard_sub_basic on them. The buffers can be written to by
callers without affecting the source string.
********************************************************************/
static char *lp_string(const char *s)
{
- static char *bufs[NUMBER_OF_STATIC_STRING_BUFS];
- static size_t buflen[NUMBER_OF_STATIC_STRING_BUFS];
- static int next = -1;
- char *ret;
- int i;
- size_t len = s?strlen(s):0;
-
- if (next == -1) {
- /* initialisation */
- for (i=0;i<NUMBER_OF_STATIC_STRING_BUFS;i++) {
- bufs[i] = NULL;
- buflen[i] = 0;
- }
- next = 0;
- }
+ size_t len = s?strlen(s):0;
+ char *ret;
- len = MAX(len+100,sizeof(pstring)); /* the +100 is for some
- substitution room */
-
- if (buflen[next] != len) {
- buflen[next] = len;
- if (bufs[next])
- free(bufs[next]);
- bufs[next] = (char *)malloc(len);
- if (!bufs[next]) {
- DEBUG(0,("out of memory in lp_string()"));
- exit(1);
- }
- }
+ if (!lp_talloc) lp_talloc = talloc_init();
+
+ ret = (char *)talloc(lp_talloc, len + 100); /* leave room for substitution */
- ret = &bufs[next][0];
- next = (next+1)%NUMBER_OF_STATIC_STRING_BUFS;
+ if (!ret) return NULL;
- if (!s)
- *ret = 0;
- else
- StrnCpy(ret,s,len-1);
+ if (!s)
+ *ret = 0;
+ else
+ StrnCpy(ret,s,len);
- trim_string(ret, "\"", "\"");
+ trim_string(ret, "\"", "\"");
- standard_sub_basic(ret);
- return(ret);
+ standard_sub_basic(ret);
+ return(ret);
}
@@ -2601,7 +2589,7 @@ BOOL lp_load(char *pszFname,BOOL global_only, BOOL save_defaults, BOOL add_ipc)
{
pstring n2;
BOOL bRetval;
-
+
add_to_file_list(pszFname);
bRetval = False;