[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] gnash ChangeLog libamf/element.cpp libamf/sol.c...
From: |
Sandro Santilli |
Subject: |
[Gnash-commit] gnash ChangeLog libamf/element.cpp libamf/sol.c... |
Date: |
Thu, 31 Jan 2008 10:27:07 +0000 |
CVSROOT: /sources/gnash
Module name: gnash
Changes by: Sandro Santilli <strk> 08/01/31 10:27:06
Modified files:
. : ChangeLog
libamf : element.cpp sol.cpp sol.h
Log message:
Some memory management, leaks plugged, mismatched new[]/delete[] fixed.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.5531&r2=1.5532
http://cvs.savannah.gnu.org/viewcvs/gnash/libamf/element.cpp?cvsroot=gnash&r1=1.7&r2=1.8
http://cvs.savannah.gnu.org/viewcvs/gnash/libamf/sol.cpp?cvsroot=gnash&r1=1.17&r2=1.18
http://cvs.savannah.gnu.org/viewcvs/gnash/libamf/sol.h?cvsroot=gnash&r1=1.7&r2=1.8
Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.5531
retrieving revision 1.5532
diff -u -b -r1.5531 -r1.5532
--- ChangeLog 30 Jan 2008 23:32:57 -0000 1.5531
+++ ChangeLog 31 Jan 2008 10:27:05 -0000 1.5532
@@ -1,3 +1,9 @@
+2008-01-31 Sandro Santilli <address@hidden>
+
+ * libamf/element.cpp, libamf/sol.{cpp,h}:
+ Some memory management, leaks plugged, mismatched
+ new[]/delete[] fixed.
+
2008-01-30 Sandro Santilli <address@hidden>
* plugin/plugin.cpp, server/vm/ASHandlers.cpp:
Index: libamf/element.cpp
===================================================================
RCS file: /sources/gnash/gnash/libamf/element.cpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- libamf/element.cpp 25 Jan 2008 18:08:00 -0000 1.7
+++ libamf/element.cpp 31 Jan 2008 10:27:06 -0000 1.8
@@ -70,7 +70,7 @@
{
// GNASH_REPORT_FUNCTION;
if (_data) {
- delete _data;
+ delete [] _data;
}
}
@@ -126,7 +126,7 @@
_name = name;
}
_length = AMF_NUMBER_SIZE;
- _data = reinterpret_cast<boost::uint8_t *>(new double);
+ _data = reinterpret_cast<boost::uint8_t *>(new char[sizeof(double)]);
memcpy(_data, &indata, _length);
return *this;
}
Index: libamf/sol.cpp
===================================================================
RCS file: /sources/gnash/gnash/libamf/sol.cpp,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -b -r1.17 -r1.18
--- libamf/sol.cpp 22 Jan 2008 01:26:03 -0000 1.17
+++ libamf/sol.cpp 31 Jan 2008 10:27:06 -0000 1.18
@@ -41,6 +41,8 @@
#include <arpa/inet.h>
#endif
+#include <boost/scoped_array.hpp>
+
using namespace std;
using namespace gnash;
@@ -74,9 +76,10 @@
// GNASH_REPORT_FUNCTION;
vector<amf::Element *>::iterator it;
- for (it = _amfobjs.begin(); it != _amfobjs.end(); it++) {
- //amf::Element *el = (*(it));
-// delete el;
+ for (it = _amfobjs.begin(); it != _amfobjs.end(); it++)
+ {
+ amf::Element *el = (*(it));
+ delete el;
}
}
@@ -234,9 +237,9 @@
}
_filesize = size;
- char *body = new char[size + 20];
- memset(body, 0, size);
- ptr = body;
+ boost::scoped_array<char> body ( new char[size + 20] );
+ memset(body.get(), 0, size);
+ ptr = body.get();
for (ita = _amfobjs.begin(); ita != _amfobjs.end(); ita++) {
amf::Element *el = (*(ita));
@@ -281,19 +284,19 @@
}
}
- _filesize = ptr - body;
+ _filesize = ptr - body.get();
int len = name.size() + sizeof(uint16_t) + 16;
- char *head = new char[len + 4];
- memset(head, 0, len);
- ptr = head;
+ boost::scoped_array<char> head ( new char[len + 4] );
+ memset(head.get(), 0, len);
+ ptr = head.get();
formatHeader(name);
for (it = _header.begin(); it != _header.end(); it++) {
*ptr++ = (*(it));
}
- ofs.write(head, _header.size());
+ ofs.write(head.get(), _header.size());
// ofs.write(body, (ptr - body));
- ofs.write(body, _filesize);
+ ofs.write(body.get(), _filesize);
ofs.close();
return true;
@@ -306,7 +309,8 @@
// GNASH_REPORT_FUNCTION;
struct stat st;
boost::uint16_t size;
- boost::uint8_t *buf, *ptr;
+ boost::scoped_array<boost::uint8_t> buf;
+ boost::uint8_t *ptr;
int bodysize;
// Make sure it's an SOL file
@@ -315,8 +319,9 @@
_filesize = st.st_size;
bodysize = st.st_size - 6;
_filespec = filespec;
- ptr = buf = new boost::uint8_t[_filesize+1];
- ifs.read(reinterpret_cast<char *>(buf), _filesize);
+ buf.reset( new boost::uint8_t[_filesize+1] );
+ ptr = buf.get();
+ ifs.read(reinterpret_cast<char *>(buf.get()), _filesize);
// skip the magic number (will check later)
ptr += 2;
@@ -353,7 +358,7 @@
ptr += 4;
AMF amf_obj;
- while ((ptr - buf) < bodysize) {
+ while ((ptr - buf.get()) < bodysize) {
amf::Element *el = new amf::Element;
ptr = amf_obj.extractVariable(el, ptr);
if (ptr != 0) {
Index: libamf/sol.h
===================================================================
RCS file: /sources/gnash/gnash/libamf/sol.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- libamf/sol.h 21 Jan 2008 22:55:27 -0000 1.7
+++ libamf/sol.h 31 Jan 2008 10:27:06 -0000 1.8
@@ -67,13 +67,35 @@
std::vector<boost::uint8_t> getHeader() { return _header; };
- // Add the AMF objects that are the data of the file
+ /// Add the AMF objects that are the data of the file
+ //
+ /// @param x
+ /// The element to add, ownership transferred
+ /// TODO: take an auto_ptr
+ ///
void addObj(amf::Element *x);
- std::vector<amf::Element *> getElements() { return _amfobjs; };
- Element *getElement(int x) { return _amfobjs[x]; };
+
+ /// Return a reference to the elements in this object
+ std::vector<amf::Element *>& getElements()
+ {
+ return _amfobjs;
+ }
+
+ /// Get an element by index
+ //
+ /// @return the element, or abort if index is wrong (eh..)
+ /// ownership of the element is retained by this object.
+ ///
+ Element *getElement(size_t x)
+ {
+ assert(x<_amfobjs.size());
+ return _amfobjs[x];
+ }
void dump();
+
//protected:
+
void setFilespec(std::string &x) { _filespec = x; };
std::string &getFilespec() { return _filespec; };
@@ -85,7 +107,10 @@
std::vector<boost::uint8_t> _data;
std::string _objname;
std::string _filespec;
+
+ /// The elements in this SharedObject, owned by it
std::vector<amf::Element *> _amfobjs;
+
int _filesize;
};
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gnash-commit] gnash ChangeLog libamf/element.cpp libamf/sol.c...,
Sandro Santilli <=