[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Lost] [Patch] Memleak in vterm
! vterm: Fix fuer Memleak beim Schliessen des in-Handles
Index: trunk/src/modules/vterm/lostio.c
===================================================================
--- trunk.orig/src/modules/vterm/lostio.c
+++ trunk/src/modules/vterm/lostio.c
@@ -44,6 +44,13 @@ read_hdl_reply terminal_read(lostio_file
size_t terminal_write(lostio_filehandle_t* handle, size_t blocksize,
size_t blockcount, void* data);
+/// Handler fuer open auf in
+static void lio_in_open(lostio_filehandle_t* fh);
+
+/// Handler fuer open auf in
+static int lio_in_close(lostio_filehandle_t* fh);
+
+
/**
* LostIO-Interface vorbereiten, ueber das die Prozesse mit vterm kommunizieren
* werden.
@@ -70,11 +77,11 @@ void init_lostio_interface()
typehandle->id = LOSTIO_TYPES_IN;
typehandle->not_found = NULL;
typehandle->pre_open = NULL;
- typehandle->post_open = NULL;
+ typehandle->post_open = &lio_in_open;
typehandle->read = &terminal_read;
typehandle->write = NULL;
typehandle->seek = NULL;
- typehandle->close = NULL;
+ typehandle->close = lio_in_close;
typehandle->link = NULL;
typehandle->unlink = NULL;
lostio_register_typehandle(typehandle);
@@ -141,5 +148,23 @@ read_hdl_reply terminal_read(lostio_file
return reply;
}
+/**
+ * LostIO-Handler der den Data-Member im Filehandle mit NULL initialisiert,
+ * damit das realloc in terminal_read nicht schief gehen kann
+ */
+static void lio_in_open(lostio_filehandle_t* fh)
+{
+ fh->data = NULL;
+}
+/**
+ * LostIO-Handler der einen allenfalls allozierten Buffer im Filehandle freigibt
+ */
+static int lio_in_close(lostio_filehandle_t* fh)
+{
+ if (fh->data) {
+ free(fh->data);
+ }
+ return 0;
+}