X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fpython%2FSWF.c;h=fd7c4231c33f7df8b78fc6af1d52634c2b0f5150;hb=84245258e84d865fb1b5a0a6a781c099946398df;hp=e01184126d482798225815872414390bec2653da;hpb=726d172d02228a2e9b084efba8d3173994343c2b;p=swftools.git diff --git a/lib/python/SWF.c b/lib/python/SWF.c index e011841..fd7c423 100644 --- a/lib/python/SWF.c +++ b/lib/python/SWF.c @@ -103,6 +103,8 @@ static PyObject* f_load(PyObject* self, PyObject* args) return NULL; swf = PyObject_New(SWFObject, &SWFClass); + mylog("+%08x(%d) f_load\n", (int)swf, swf->ob_refcnt); + memset(&swf->swf, 0, sizeof(SWF)); swf->filename = strdup(filename); @@ -121,11 +123,15 @@ static PyObject* f_load(PyObject* self, PyObject* args) return 0; } close(fi); - swf->swf.firstTag = 0; swf->taglist = taglist_new2(swf->swf.firstTag); + if(swf->taglist == NULL) { + return NULL; + } + + swf_FreeTags(&swf->swf); + swf->swf.firstTag = 0; - mylog("+%08x(%d) load\n", (int)self, self->ob_refcnt); return (PyObject*)swf; } //---------------------------------------------------------------------------- @@ -148,20 +154,25 @@ static PyObject * swf_save(PyObject* self, PyObject* args, PyObject* kwargs) if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|si", kwlist, &filename, &compress)) return NULL; + + mylog(" %08x(%d) f_save filename=%s compress=%d\n", (int)self, self->ob_refcnt, filename, compress); // keyword arg compress (=1) forces compression if(compress) swf->compressed = 1; swf->firstTag = taglist_getTAGs(swfo->taglist); + if(!swf->firstTag) + return NULL; // fix the file, in case it is empty or not terminated properly { TAG*tag = swf->firstTag; if(!tag) tag = swf->firstTag = swf_InsertTag(0,ST_END); - while(tag && tag->next) + while(tag && tag->next) { tag = tag->next; + } if(tag->id != ST_END) { tag = swf_InsertTag(tag,ST_END); } @@ -186,8 +197,10 @@ static PyObject * swf_save(PyObject* self, PyObject* args, PyObject* kwargs) } } close(fi); - - swf->firstTag = 0; + + /* TODO: why is this segfaulting?? */ + /* swf_FreeTags(swf); + swf->firstTag = 0;*/ return PY_NONE; } @@ -198,6 +211,8 @@ static PyObject * swf_writeCGI(PyObject* self, PyObject* args) if(!self || !PyArg_ParseTuple(args,"")) return NULL; swf->swf.firstTag = taglist_getTAGs(swf->taglist); + if(!swf->swf.firstTag) + return NULL; swf_WriteCGI(&swf->swf); swf->swf.firstTag = 0; return PY_NONE;