Hi Matt,
On Wed, Apr 11, 2001 at 10:54:26PM -0700, Matt wrote:
> in resmgr.c in function gfxr_get_font(),
>
> if (!res) {
> res = malloc(sizeof(gfx_resource_t));
> res->scaled_data.font = NULL;
> res->ID = ((restype << 16) | nr);
> res->lock_sequence_nr = state->tag_lock_counter;
> res->mode = hash;
> sbtree_set(tree, nr, (void *) res);
> } else {
> gfxr_free_font(res->unscaled_data.font);
> }
>
> res->unscaled_data.font = font;
> free(res);
>
> return font;
>
>
> I added the free(res) to correct a potential memory leak. This doesn't
> make sense though -- why assign font to res if it's just about to go out
> of scope? Is this assignment supposed to be the other way around?
No, it's all right the way it was- Either 'res' is a pointer to an existing entry
in a static binary tree�(a simple container class- I suspect that qsort() and
bsearch() might be slightly faster than this, but I think I had some reason
to assume it was a good idea at the time), or it's a new entry which is added
with sbtree_set(). In either case, the memory is handled by the sbtree_t
structure for the specified resource type; freeing the resource entry at this
point orphans the pointer to the actual translated resources and will cause
the freed memory to be free()d again during deinitialization of the resource
manager.
I'll diff the version you provided and apply the other changes. Thanks for
checking!
llap,
Christoph