Re: segmentation fault in t_splay() calling Tcl_Alloc()

From: Anthony Davis (adavis_at_addpower.com)
Date: 10/07/03


Date: 7 Oct 2003 08:25:34 -0700


> Does your program call malloc()/free() itself besides Tcl_Alloc()?
> Have you checked the pointers there?

No I do not have any explicit calls to malloc()/free() anywhere in the
application, I use only Tcl_Alloc and Tcl_Free().

The call to Tcl_Alloc is actually being made from within
Tcl_NewStringObj if this makes a difference at all.

Here is the code snippet where the error occurs:

  /* the function PVK_read() is a third party function for reading a
   * proprietary data file, it returns a char*. szResult is previously
   * allocated with Tcl_Alloc the length defined in the file's
dictionary +1
   */
  if(PVX_ERROR==(int)(cbBytesRead=PVK_read(pclFilePtr->fh,szResult,
                                       
pclFilePtr->pvkinf->rsz,nPvxRdId))){
    PclSetObjResultPvxError(interp,"pclread");
    return TCL_ERROR;
  }

  szResult[cbBytesRead+1]='\0';
  /* segmentation fault is on this line in Tcl_NewStringObj */
  Tcl_SetObjResult(interp,Tcl_NewStringObj(szResult,strlen(szResult)));
  Tcl_Free(szResult);
  return TCL_OK;

Hope this helps, I would be glad to find out it is something I am
doing wrong if there is anything you can see let me know.
Anthony



Relevant Pages

  • Re: sizeof(ptr) = ?
    ... A void * has the same representation as a char *. ... Char pointers which require additional data ... iff the default offset is 0. ...
    (comp.lang.c)
  • Re: Comments requested: brief summary of C
    ... ``A char holds a single byte. ... ``A string is a contiguous sequence of characters terminated ... pointed to by city. ... pointers and arrays are often used ...
    (comp.lang.c)
  • Re: Any way to take a word as input from stdin ?
    ... You want to sort many words, so you will need to store ... number of pointers to char (which can be reallocated if it proves to be ... The pointers to char ... That's why you use dynamic allocation - it means ...
    (comp.lang.c)
  • Re: Can C do it ?
    ... looked above my present understanding and expectation of programming. ... the first one with pointers, ... int main ... char Verb2; ...
    (comp.lang.c)
  • Re: Function Problem
    ... > but fnReplace takes pointers to strings of length 16. ... > void fnReplace (char *RplStr) ...
    (microsoft.public.windowsce.embedded.vc)