Strange malloc problem..

From: stephen henry (stehenry_at_yahoo.com)
Date: 08/20/04


Date: 20 Aug 2004 03:13:01 -0700

Hi all,

I am having great difficulty trying to figure out what is wrong with
my code and was hoping someone out there could lend a hand. The code
is too long to post here in its entirety, but i've included the
relevant sections.

I have tree structures. The first two are in the same file:

typedef struct tag_function_profile{

  char *function_name;
  char *source_file;
  unsigned int line_number;

}function_profile_t;

typedef struct function_t_tag{

  function_profile_t *function_profile;
  unsigned int number_of_children;
  struct function_t_tag *child;
  struct function_t_tag *parent;

  // Profiling entries.
  comms_t *comms;

} function_t;

The third, comms_t, is kept in another file and is as follows:

typedef struct tag_comms{
  unsigned int number_of_comms_data;
  unsigned int current_comms_data;
  comms_data_t *data;
}comms_t;

The problem I am having is that sometimes when I write to comms in
function_t type structure, having already allocated memory for it, it
overwrites the function_name pointer in the function_profile_t
structure -including the comms structure as I would expect. What is
going on here? I thought it may be that the compiler hasn't been able
to recongnise what a comm_t structure was when it was compiling the
source with function_t in it, since it was a bit of a coincidence that
the first entry of the structure was being overwritten. Either that or
somesort of malloc problem, but I've looked and looked and there
doesn't appear to be any such problems. Any ideas what could be
causing this?

Thanks,

Stephen



Relevant Pages

  • Re: int, float
    ... typedef struct _MF { ... unsigned int e: 8; ... > your platform encodes a float. ... > your compiler. ...
    (comp.lang.cpp)
  • Re: using member address of an unaligned structure
    ... "warning use of address of unaligned structure member" ... change the declaration of id to unsigned int ... from the compiler and the output of the program. ...
    (comp.lang.c)
  • Re: Checking endianess in compile time
    ... > automatically check if the bitfields are regarded properly by the ... > unsigned int tffca: 1; ... > Is there a way to check if the compiler considers bitfield ten ...
    (comp.lang.c)
  • STL std::inplace_merge and Visual 2008 performance
    ... Is there an obvious error on the compiler flags used? ... unsigned int ToRemoveNbr = 100; ... QueryPerformanceCounter(&timeBefore); ...
    (microsoft.public.vc.stl)
  • Re: [HP ProLiant WatchDog driver] hpwdt HP WatchDog Patch
    ... specific HW Timer located in the HP ProLiant iLO 2 ASIC. ... +typedef struct _SMBIOSEntryPoint { ... +static unsigned int new_margin; ... +static void *gpVirtRomCRUAddr; ...
    (Linux-Kernel)