freetype-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

=?US-ASCII?Q?Re: [Devel] Bug in FT=5FNew=5FMemory=5FFace??=


From: Michael Pfeiffer
Subject: =?US-ASCII?Q?Re: [Devel] Bug in FT=5FNew=5FMemory=5FFace??=
Date: Mon, 11 Jun 2001 21:52:39 +0000

>6/11/01 7:51:14 AM, Werner LEMBERG <address@hidden> wrote:
>
>>> >> Now I wanted to optimize this application and read
>>> >> the font file as it is already in memory with 
>>> >> FT_New_Memory_Face(), but now the application crashes
>>> >> or FT_Load_Glyph() returns with error code 2945.
>>> 
>>> Same problem with this version. I used the version in the
>>> cvs repository.
>>
>>Can you provide a very small sample code program which exhibits this
>>behaviour (or can you modify one of the test programs)?  Or can you
>>run a memory tool (or a debugger) on it to check why it crashes?
>
>Ok I will write a sample program, so I can at least test if the
>bug is in my program or in FreeType.

I have modified ftstring.c to use FT_New_Memory_Face(..., buffer, ..., &
face).
When the memory for the buffer is freed after this function call,
ftstring crashes when the test string is drawn.
ftstring seems to work properly when the buffer is not deleted. 
If this is the intended behavior, please alter the documentation.

Question: Takes FT_New_Memory_Face ownership of the
buffer and frees it the memory when the face is deleted FT_Done_Face()
or do I have to delete the buffer myself?

Thanks,
Michael

static FT_Error New_Face( FT_Library  library,
                          const char* filepathname,
                          FT_Long     face_index,
                          FT_Face     *aface ) {
  FT_Error error = -1;
  FILE* f = fopen(filepathname, "rb");
  if (f) {
    char* buf = NULL;
    int i = 0;
    int size = 0;
    int c;
    int length;
    while ((c = fgetc(f)) != EOF) {
      if (i == size) {
        size += 4096;
        buf = (char *)realloc(buf, size);
      }
      buf[i++] = c;
    }
    length = i;

    fclose(f);
    error = FT_New_Memory_Face(library, buf, length, face_index, aface);
    free(buf); // <-
  }
  return error;
}





reply via email to

[Prev in Thread] Current Thread [Next in Thread]