diff options
author | Joel Bosveld <joel@JOEL-UBUNTU.(none)> | 2007-12-15 17:19:28 +0900 |
---|---|---|
committer | Joel Bosveld <joel@JOEL-UBUNTU.(none)> | 2007-12-15 17:19:28 +0900 |
commit | 97b7ad3bb10884b5878ca9e4dcb10f011a02ee3b (patch) | |
tree | 40601bddd75d639f80a1b01982199798dc2e879b | |
parent | 006ead3e85c22e01a3b565d9fec15970f1f9904f (diff) | |
download | cubedbus-97b7ad3bb10884b5878ca9e4dcb10f011a02ee3b.tar.gz cubedbus-97b7ad3bb10884b5878ca9e4dcb10f011a02ee3b.tar.bz2 |
Removed all free's, as "free(strline);" seems to be causing a lockup.
-rw-r--r-- | cubedbusModel.c.in | 62 |
1 files changed, 32 insertions, 30 deletions
diff --git a/cubedbusModel.c.in b/cubedbusModel.c.in index 4898466..1a9af15 100644 --- a/cubedbusModel.c.in +++ b/cubedbusModel.c.in @@ -10,7 +10,7 @@ static bool cubedbusDeleteModelObject (CubedbusObject *obj); static bool cubedbusModifyModelObject (CubedbusObject *obj, CompOption *option, int nOption); static bool cubedbusAddModelObject (CubedbusObject *obj, CompOption *option, int nOption); -char *getLine (FILE *fp); +static char *getLine (FILE *fp); typedef struct _vect3d { @@ -85,8 +85,8 @@ cubedbusAddModelObject (CubedbusObject *obj, CompOption *option, int nOption) int nNormal=0; int nTexture=0; int nMtllib=0; - + /* First pass - count how much data we need to store */ FILE *fp = fopen(getStringOptionNamed (option, nOption, "file", ""), "r"); @@ -100,36 +100,39 @@ cubedbusAddModelObject (CubedbusObject *obj, CompOption *option, int nOption) { tmpType = malloc ( sizeof (char *) * 2); tmpType[0]=strsep(&strline," "); + if(tmpType[0] == NULL) { compLogMessage(obj->s->display, "cubedbus", CompLogLevelWarn, "Error reading file..."); - free(strline); + //free(strline); return FALSE; - } + } if(!strcmp(tmpType[0], "v" )) nVertex++; if(!strcmp(tmpType[0], "vn")) nNormal++; if(!strcmp(tmpType[0], "vt")) nTexture++; - + if(!strcmp(tmpType[0], "mtllib")) - { + { while(1) - { + { tmpType[1]=strsep(&strline," "); if(tmpType[1]==NULL) break; if(!strcmp(tmpType[1],"")) continue; nMtllib++; } } - free(strline); + + //free(strline); strline=NULL; } - + + fclose (fp); /* Second pass - fill arrays */ - + vect3d *vertex=malloc(sizeof(vect3d)*nVertex); vect3d *normal=malloc(sizeof(vect3d)*nNormal); vect2d *texture=malloc(sizeof(vect2d)*nTexture); @@ -153,7 +156,7 @@ cubedbusAddModelObject (CubedbusObject *obj, CompOption *option, int nOption) if(tmpType[0] == NULL) { compLogMessage(obj->s->display, "cubedbus", CompLogLevelWarn, "Error reading file..."); - free(strline); + //free(strline); return FALSE; } @@ -193,11 +196,10 @@ cubedbusAddModelObject (CubedbusObject *obj, CompOption *option, int nOption) nMtllib++; } } - free(strline); + //free(strline); strline=NULL; } - fclose (fp); @@ -245,7 +247,7 @@ cubedbusAddModelObject (CubedbusObject *obj, CompOption *option, int nOption) if(tmpType[0] == NULL) { compLogMessage(obj->s->display, "cubedbus", CompLogLevelWarn, "Error reading file..."); - free(strline); + //free(strline); return FALSE; } if(!strcmp(tmpType[0], "newmtl")) @@ -254,7 +256,7 @@ cubedbusAddModelObject (CubedbusObject *obj, CompOption *option, int nOption) if(tmpType[1] == NULL) { compLogMessage(obj->s->display, "cubedbus", CompLogLevelWarn, "Error reading file..."); - free(strline); + //free(strline); return FALSE; } mtlPtr->next = malloc (sizeof (mtlStruct) ); @@ -325,7 +327,7 @@ cubedbusAddModelObject (CubedbusObject *obj, CompOption *option, int nOption) mtlPtr->tex=NULL; } } - free(strline); + //free(strline); strline=NULL; } @@ -342,7 +344,7 @@ cubedbusAddModelObject (CubedbusObject *obj, CompOption *option, int nOption) int polyCount; char **tempInfo; /* used to check for realloc */ char **tmpPtr; /* used to chec value of vertex/texture/normal numbers */ - + /* Final (third) pass - use data */ fp = fopen(getStringOptionNamed (option, nOption, "file", ""), "r"); @@ -362,8 +364,8 @@ cubedbusAddModelObject (CubedbusObject *obj, CompOption *option, int nOption) if(tmpType==NULL) { compLogMessage(obj->s->display, "cubedbus", CompLogLevelWarn, "out of mem"); - free(tmpType); - free(strline); + //free(tmpType); + //free(strline); return FALSE; } @@ -371,7 +373,7 @@ cubedbusAddModelObject (CubedbusObject *obj, CompOption *option, int nOption) if(tmpType[0] == NULL) { compLogMessage(obj->s->display, "cubedbus", CompLogLevelWarn, "Error reading file..."); - free(strline); + //free(strline); return FALSE; } if(!strcmp(tmpType[0], "f")) @@ -386,8 +388,8 @@ cubedbusAddModelObject (CubedbusObject *obj, CompOption *option, int nOption) if(tempInfo==NULL) { compLogMessage(obj->s->display, "cubedbus", CompLogLevelWarn, "out of mem"); - free(tmpType); - free(strline); + //free(tmpType); + //free(strline); return FALSE; } tmpType=tempInfo; @@ -395,7 +397,7 @@ cubedbusAddModelObject (CubedbusObject *obj, CompOption *option, int nOption) tmpType[polyCount]=strsep(&strline," "); if(tmpType[polyCount] == NULL) { - free(strline); + //free(strline); break; } @@ -435,15 +437,15 @@ cubedbusAddModelObject (CubedbusObject *obj, CompOption *option, int nOption) if(tempInfo==NULL) { compLogMessage(obj->s->display, "cubedbus", CompLogLevelWarn, "out of mem"); - free(tmpType); - free(strline); + //free(tmpType); + //free(strline); return FALSE; } tmpType=tempInfo; tmpType[1]=strsep(&strline," "); if(tmpType[1]== NULL) { - free(strline); + //free(strline); compLogMessage(obj->s->display, "cubedbus", CompLogLevelWarn, "no mtl specified"); return FALSE; } @@ -491,7 +493,7 @@ cubedbusAddModelObject (CubedbusObject *obj, CompOption *option, int nOption) } } } - free(strline); + //free(strline); strline=NULL; } @@ -550,7 +552,7 @@ cubedbusDrawModelObject (CubedbusObject *obj) * NOTE: returns NULL if error occurs * *************************************/ -char * +static char * getLine (FILE *fp) { char *tmp=NULL; @@ -561,11 +563,11 @@ getLine (FILE *fp) while( (c=getc(fp) ) != EOF ) { - tmp=realloc(tmp, sizeof(char)*(n+1)); + tmp=realloc(strline, sizeof(char)*(n+1)); if(tmp == NULL) { compLogMessage(NULL, "cubedbus", CompLogLevelWarn, "Error reading file - out of mem"); - free(strline); + //free(strline); return NULL; } strline=tmp; /* The strline array should now be big enough to hold all characters read so far, plus the one being read */ |