summaryrefslogtreecommitdiff
path: root/source4/lib
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2005-07-10 01:10:09 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:19:29 -0500
commit76ecf81428c161a98a5621b55a64cb8515f80585 (patch)
tree542798f01d1582b00d7d20a93effba33f98ee1fc /source4/lib
parentc6881d1e650fd284a366af76f5a214a5de05cc0c (diff)
downloadsamba-76ecf81428c161a98a5621b55a64cb8515f80585.tar.gz
samba-76ecf81428c161a98a5621b55a64cb8515f80585.tar.bz2
samba-76ecf81428c161a98a5621b55a64cb8515f80585.zip
r8273: fixed some memory leaks in smbscript. This required converting
file_load() to use talloc, which impacted quite a few bits of code, including our smb.conf processing. took the opportunity to remove the gloabls in params.c while doing this (This used to be commit b220756cb4f1d201ba3e771ca67e4bfae5eae748)
Diffstat (limited to 'source4/lib')
-rw-r--r--source4/lib/util_file.c33
1 files changed, 11 insertions, 22 deletions
diff --git a/source4/lib/util_file.c b/source4/lib/util_file.c
index e02198754d..a7d29d1a1d 100644
--- a/source4/lib/util_file.c
+++ b/source4/lib/util_file.c
@@ -190,18 +190,18 @@ char *fgets_slash(char *s2,int maxlen,XFILE *f)
load a file into memory from a fd.
****************************************************************************/
-char *fd_load(int fd, size_t *size)
+char *fd_load(int fd, size_t *size, TALLOC_CTX *mem_ctx)
{
struct stat sbuf;
char *p;
if (fstat(fd, &sbuf) != 0) return NULL;
- p = (char *)malloc(sbuf.st_size+1);
+ p = (char *)talloc_size(mem_ctx, sbuf.st_size+1);
if (!p) return NULL;
if (read(fd, p, sbuf.st_size) != sbuf.st_size) {
- SAFE_FREE(p);
+ talloc_free(p);
return NULL;
}
p[sbuf.st_size] = 0;
@@ -214,7 +214,7 @@ char *fd_load(int fd, size_t *size)
/****************************************************************************
load a file into memory
****************************************************************************/
-char *file_load(const char *fname, size_t *size)
+char *file_load(const char *fname, size_t *size, TALLOC_CTX *mem_ctx)
{
int fd;
char *p;
@@ -224,7 +224,7 @@ char *file_load(const char *fname, size_t *size)
fd = open(fname,O_RDONLY);
if (fd == -1) return NULL;
- p = fd_load(fd, size);
+ p = fd_load(fd, size, mem_ctx);
close(fd);
@@ -254,12 +254,12 @@ void *map_file(char *fname, size_t size)
}
#endif
if (!p) {
- p = file_load(fname, &s2);
+ p = file_load(fname, &s2, talloc_autofree_context());
if (!p) return NULL;
if (s2 != size) {
DEBUG(1,("incorrect size for %s - got %d expected %d\n",
fname, s2, size));
- if (p) free(p);
+ talloc_free(p);
return NULL;
}
}
@@ -308,12 +308,12 @@ static char **file_lines_parse(char *p, size_t size, int *numlines)
load a file into memory and return an array of pointers to lines in the file
must be freed with file_lines_free().
****************************************************************************/
-char **file_lines_load(const char *fname, int *numlines)
+char **file_lines_load(const char *fname, int *numlines, TALLOC_CTX *mem_ctx)
{
char *p;
size_t size;
- p = file_load(fname, &size);
+ p = file_load(fname, &size, mem_ctx);
if (!p) return NULL;
return file_lines_parse(p, size, numlines);
@@ -324,12 +324,12 @@ load a fd into memory and return an array of pointers to lines in the file
must be freed with file_lines_free(). If convert is true calls unix_to_dos on
the list.
****************************************************************************/
-char **fd_lines_load(int fd, int *numlines)
+char **fd_lines_load(int fd, int *numlines, TALLOC_CTX *mem_ctx)
{
char *p;
size_t size;
- p = fd_load(fd, &size);
+ p = fd_load(fd, &size, mem_ctx);
if (!p) return NULL;
return file_lines_parse(p, size, numlines);
@@ -337,17 +337,6 @@ char **fd_lines_load(int fd, int *numlines)
/****************************************************************************
-free lines loaded with file_lines_load
-****************************************************************************/
-void file_lines_free(char **lines)
-{
- if (!lines) return;
- SAFE_FREE(lines[0]);
- SAFE_FREE(lines);
-}
-
-
-/****************************************************************************
take a lislist of lines and modify them to produce a list where \ continues
a line
****************************************************************************/