Skip to content
Snippets Groups Projects
Commit 4965951a authored by Lars Kanis's avatar Lars Kanis
Browse files

fix double free in FXMemoryStream#giveBuffer

The Ruby String buffer was free'd by GC and FXMemoryStream#close
parent a3fcce8f
No related branches found
No related tags found
No related merge requests found
...@@ -44,7 +44,7 @@ public: ...@@ -44,7 +44,7 @@ public:
return self->open(save_or_load,data); return self->open(save_or_load,data);
} }
} }
// Take buffer away from stream // Take buffer away from stream
VALUE takeBuffer() { VALUE takeBuffer() {
FXuchar* buffer; FXuchar* buffer;
...@@ -54,19 +54,23 @@ public: ...@@ -54,19 +54,23 @@ public:
FXFREE(&buffer); FXFREE(&buffer);
return result; return result;
} }
/// Give buffer to stream /// Give buffer to stream
void giveBuffer(VALUE str){ void giveBuffer(VALUE str){
FXuchar* copy = NULL;
Check_Type(str,T_STRING); Check_Type(str,T_STRING);
FXuchar* buffer=reinterpret_cast<FXuchar*>(StringValuePtr(str)); FXuchar* buffer=reinterpret_cast<FXuchar*>(StringValuePtr(str));
FXuval sp=RSTRING_LEN(str); FXuval sp=RSTRING_LEN(str);
self->giveBuffer(buffer,sp); if( FXMALLOC(&copy, FXuchar *, sp)) {
memcpy(copy, buffer, sp);
self->giveBuffer(copy,sp);
}
} }
} }
/// Get position /// Get position
FXlong position() const; FXlong position() const;
/// Destructor /// Destructor
virtual ~FXMemoryStream(); virtual ~FXMemoryStream();
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment