Take an incoming const char * pointer and return an allocated
array that must be freed. Don't expose the internal optimization
of file_lines_parse_internal() breaking the passed in string
into lines.
Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Guenther Deschner <gd@samba.org>
_PUBLIC_ char *fd_load(int fd, size_t *size, size_t maxsize, TALLOC_CTX *mem_ctx);
-char **file_lines_parse(char *p, size_t size, int *numlines, TALLOC_CTX *mem_ctx);
+char **file_lines_parse(const char *p, size_t size, int *numlines, TALLOC_CTX *mem_ctx);
/**
load a file into memory
return file_lines_parse_internal(p, size, numlines, mem_ctx);
}
-_PUBLIC_ char **file_lines_parse(char *p,
+_PUBLIC_ char **file_lines_parse(const char *p_in,
size_t size,
int *numlines,
TALLOC_CTX *mem_ctx)
{
+ /*
+ * Copy the incoming string so it can end up
+ * being owned by the returned pointer and
+ * freed when that is.
+ */
+ char *p = talloc_strdup(mem_ctx, p_in);
+ if (p == NULL) {
+ return NULL;
+ }
return file_lines_parse_internal(p, size, numlines, mem_ctx);
}