From 7d09a4c6f251d24bd87f3c786e835e84255bcabf Mon Sep 17 00:00:00 2001 From: Kris De Gussem Date: Sat, 19 Nov 2011 19:50:23 +0100 Subject: fix pointer usage after releasing memory (bzr r10745) --- src/io/uristream.cpp | 20 +++++++++++--------- src/io/uristream.h | 9 +++------ 2 files changed, 14 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/io/uristream.cpp b/src/io/uristream.cpp index 7397d725f..19994bc82 100644 --- a/src/io/uristream.cpp +++ b/src/io/uristream.cpp @@ -98,27 +98,26 @@ UriInputStream::UriInputStream(Inkscape::URI &source) scheme = SCHEME_FILE; else if (strncmp("data", schemestr, 4)==0) scheme = SCHEME_DATA; - //printf("in schemestr:'%s' scheme:'%d'\n", schemestr, scheme); - gchar *cpath = NULL; + gchar *cpath = NULL; switch (scheme) { case SCHEME_FILE: cpath = uri.toNativeFilename(); - //printf("in cpath:'%s'\n", cpath); inf = fopen_utf8name(cpath, FILE_READ); - //inf = fopen(cpath, "rb"); - g_free(cpath); if (!inf) { Glib::ustring err = "UriInputStream cannot open file "; err += cpath; + g_free(cpath); throw StreamException(err); } + else{ + g_free(cpath); + } break; case SCHEME_DATA: data = (unsigned char *) uri.getPath(); - //printf("in data:'%s'\n", data); dataPos = 0; dataLen = strlen((const char *)data); break; @@ -131,15 +130,18 @@ UriInputStream::UriInputStream(Inkscape::URI &source) * */ UriInputStream::UriInputStream(FILE *source, Inkscape::URI &uri) - throw (StreamException): inf(source), - uri(uri) + throw (StreamException): uri(uri), + inf(source), + data(0), + dataPos(0), + dataLen(0), + closed(false) { scheme = SCHEME_FILE; if (!inf) { Glib::ustring err = "UriInputStream passed NULL"; throw StreamException(err); } - closed = false; } /** diff --git a/src/io/uristream.h b/src/io/uristream.h index 67d2f34d7..16b1b0894 100644 --- a/src/io/uristream.h +++ b/src/io/uristream.h @@ -50,18 +50,15 @@ public: virtual int get() throw(StreamException); private: - - bool closed; - + Inkscape::URI &uri; FILE *inf; //for file: uris unsigned char *data; //for data: uris int dataPos; // current read position in data field int dataLen; // length of data buffer - - Inkscape::URI &uri; - + bool closed; int scheme; + }; // class UriInputStream -- cgit v1.2.3