Problem with memory in C function

From: Diogo Biazus <diogo(at)ikono(dot)com(dot)br>
To: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Problem with memory in C function
Date: 2004-03-26 20:29:21
Message-ID: 406492A1.6030202@ikono.com.br
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi folks,

Sorry to send this email twice, but I'm having troubles with my email
server.
I'm having troubles writing a function that reads a file from fisk and
return a bytea to database.
Can anyone help me?

I read the entire file into a (char *) and then return it as a bytea:

fseek(file, 0L, SEEK_END);
tamanhoArquivo = ftell(file);
rewind(file);

fileContent = palloc(fileSize + 1);
if(fileContent == NULL )
{
elog(ERROR, "Error alocating memory (%i bytes)", fileSize + 1);
}

fread(fileContent, fileSize, 1, file);
fclose(file);
PG_RETURN_BYTEA_P((bytea *) fileContent);

And, when I call the funcion in psql, it gives me the following message:
ERROR: Memory exhausted in AllocSetAlloc(879718306)

Am I doing something wrong?

TIA,

--
Diogo Biazus
diogo(at)ikono(dot)com(dot)br
http://www.ikono.com.br

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Bruno Wolff III 2004-03-26 20:42:12 Re: Another date / time question
Previous Message Pablo Montilla 2004-03-26 20:25:44 Waiting for Commit