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

Skip to content

Commit 1d55923

Browse files
committed
some fixes regarding caveats part of article at http://www.postgresql.org/docs/6.3/static/c3102.htm
1 parent 8131f9c commit 1d55923

1 file changed

Lines changed: 12 additions & 12 deletions

File tree

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

Lines changed: 12 additions & 12 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 *)malloc(argv0_size + 1);
61+
command = (char *)palloc(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-
free(command);
72+
pfree(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 *)malloc(argv0_size + 1);
94+
command = (char *)palloc(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 *)malloc(1);
104+
result = (char *)palloc(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 *)malloc(VARHDRSZ + strlen(result));
122+
result_text = (text *)palloc(VARHDRSZ + strlen(result));
123123
#ifdef SET_VARSIZE
124124
SET_VARSIZE(result_text, VARHDRSZ + strlen(result));
125125
#else
@@ -224,7 +224,7 @@ extern DLLIMPORT Datum sys_fileread(PG_FUNCTION_ARGS) {
224224
FILE *file;
225225

226226
argv0_size = VARSIZE(argv0) - VARHDRSZ;
227-
filename = (char *)malloc(argv0_size + 1);
227+
filename = (char *)palloc(argv0_size + 1);
228228

229229
memcpy(filename, VARDATA(argv0), argv0_size);
230230
filename[argv0_size] = '\0';
@@ -239,7 +239,7 @@ extern DLLIMPORT Datum sys_fileread(PG_FUNCTION_ARGS) {
239239
len = ftell(file);
240240
fseek(file, 0, SEEK_SET);
241241

242-
buffer=(char *)malloc(len + 1);
242+
buffer=(char *)palloc(len + 1);
243243
if (!buffer)
244244
{
245245
fclose(file);
@@ -249,25 +249,25 @@ extern DLLIMPORT Datum sys_fileread(PG_FUNCTION_ARGS) {
249249
fread(buffer, len, 1, file);
250250
fclose(file);
251251

252-
result = (char *)malloc(2*len + 1);
252+
result = (char *)palloc(2*len + 1);
253253
for (i=0, j=0; i<len; i++)
254254
{
255255
result[j++] = table[(buffer[i] >> 4) & 0x0f];
256256
result[j++] = table[ buffer[i] & 0x0f];
257257
}
258258
result[j] = '\0';
259259

260-
result_text = (text *)malloc(VARHDRSZ + strlen(result));
260+
result_text = (text *)palloc(VARHDRSZ + strlen(result));
261261
#ifdef SET_VARSIZE
262262
SET_VARSIZE(result_text, VARHDRSZ + strlen(result));
263263
#else
264264
VARATT_SIZEP(result_text) = strlen(result) + VARHDRSZ;
265265
#endif
266266
memcpy(VARDATA(result_text), result, strlen(result));
267267

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

272272
PG_RETURN_POINTER(result_text);
273273
}

0 commit comments

Comments
 (0)