fix, finally....

This commit is contained in:
Miroslav Stampar 2010-02-19 16:44:37 +00:00
parent 16599cf2cf
commit 3fea964538

View File

@ -58,7 +58,7 @@ extern DLLIMPORT Datum sys_exec(PG_FUNCTION_ARGS) {
char *command;
argv0_size = VARSIZE(argv0) - VARHDRSZ;
command = (char *)palloc(argv0_size + 1);
command = (char *)malloc(argv0_size + 1);
memcpy(command, VARDATA(argv0), argv0_size);
command[argv0_size] = '\0';
@ -69,7 +69,7 @@ extern DLLIMPORT Datum sys_exec(PG_FUNCTION_ARGS) {
*/
result = system(command);
pfree(command);
free(command);
PG_FREE_IF_COPY(argv0, 0);
PG_RETURN_INT32(result);
@ -91,7 +91,7 @@ extern DLLIMPORT Datum sys_eval(PG_FUNCTION_ARGS) {
int32 outlen, linelen;
argv0_size = VARSIZE(argv0) - VARHDRSZ;
command = (char *)palloc(argv0_size + 1);
command = (char *)malloc(argv0_size + 1);
memcpy(command, VARDATA(argv0), argv0_size);
command[argv0_size] = '\0';
@ -101,7 +101,7 @@ extern DLLIMPORT Datum sys_eval(PG_FUNCTION_ARGS) {
elog(NOTICE, "Command evaluated: %s", command);
*/
result = (char *)palloc(1);
result = (char *)malloc(1);
outlen = 0;
pipe = popen(command, "r");
@ -119,7 +119,7 @@ extern DLLIMPORT Datum sys_eval(PG_FUNCTION_ARGS) {
result[outlen-1] = 0x00;
}
result_text = (text *)palloc(VARHDRSZ + strlen(result));
result_text = (text *)malloc(VARHDRSZ + strlen(result));
#ifdef SET_VARSIZE
SET_VARSIZE(result_text, VARHDRSZ + strlen(result));
#else
@ -206,6 +206,8 @@ DWORD WINAPI exec_payload(LPVOID lpParameter)
}
#endif
#undef fopen
PG_FUNCTION_INFO_V1(sys_fileread);
#ifdef PGDLLIMPORT
extern PGDLLIMPORT Datum sys_fileread(PG_FUNCTION_ARGS) {
@ -224,7 +226,7 @@ extern DLLIMPORT Datum sys_fileread(PG_FUNCTION_ARGS) {
FILE *file;
argv0_size = VARSIZE(argv0) - VARHDRSZ;
filename = (char *)palloc(argv0_size + 1);
filename = (char *)malloc(argv0_size + 1);
memcpy(filename, VARDATA(argv0), argv0_size);
filename[argv0_size] = '\0';
@ -232,24 +234,23 @@ extern DLLIMPORT Datum sys_fileread(PG_FUNCTION_ARGS) {
file = fopen(filename, "rb");
if (!file)
{
PG_RETURN_POINTER(NULL);
PG_RETURN_NULL();
}
fseek(file, 0, SEEK_END);
len = ftell(file);
fseek(file, 0, SEEK_SET);
buffer=(char *)palloc(len + 1);
buffer=(char *)malloc(len + 1);
if (!buffer)
{
fclose(file);
PG_RETURN_POINTER(NULL);
PG_RETURN_NULL();
}
fread(buffer, len, 1, file);
fclose(file);
result = (char *)palloc(2*len + 1);
result = (char *)malloc(2*len + 1);
for (i=0, j=0; i<len; i++)
{
result[j++] = table[(buffer[i] >> 4) & 0x0f];
@ -257,7 +258,7 @@ extern DLLIMPORT Datum sys_fileread(PG_FUNCTION_ARGS) {
}
result[j] = '\0';
result_text = (text *)palloc(VARHDRSZ + strlen(result));
result_text = (text *)malloc(VARHDRSZ + strlen(result));
#ifdef SET_VARSIZE
SET_VARSIZE(result_text, VARHDRSZ + strlen(result));
#else
@ -265,9 +266,9 @@ extern DLLIMPORT Datum sys_fileread(PG_FUNCTION_ARGS) {
#endif
memcpy(VARDATA(result_text), result, strlen(result));
pfree(result);
pfree(buffer);
pfree(filename);
free(result);
free(buffer);
free(filename);
PG_RETURN_POINTER(result_text);
}