[xiph-cvs] cvs commit: icecast/src format.h format_vorbis.c source.c

Jack Moffitt jack at xiph.org
Fri Jan 4 16:29:28 PST 2002



jack        02/01/04 16:29:28

  Modified:    src      format.h format_vorbis.c source.c
  Log:
  Thanks to Ciaran for realizing that we werne't freeing the format plugins
  memory on source exits.  This caused a small but noticable memory leak.
  
  The fix was to add a new method to the format_plugin object -
  free_plugin() - and have the source thread call this on shutdown.

Revision  Changes    Path
1.2       +1 -0      icecast/src/format.h

Index: format.h
===================================================================
RCS file: /usr/local/cvsroot/icecast/src/format.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- format.h	2001/09/10 02:21:51	1.1
+++ format.h	2002/01/05 00:29:27	1.2
@@ -23,6 +23,7 @@
 
         refbuf_t *(*get_buffer)(struct _format_plugin_tag *self, char *data, unsigned long len);
         refbuf_queue_t *(*get_predata)(struct _format_plugin_tag *self);
+	void (*free_plugin)(struct _format_plugin_tag *self);
 
         /* for internal state management */
         void *_state;

1.2       +26 -0     icecast/src/format_vorbis.c

Index: format_vorbis.c
===================================================================
RCS file: /usr/local/cvsroot/icecast/src/format_vorbis.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- format_vorbis.c	2001/09/10 02:21:51	1.1
+++ format_vorbis.c	2002/01/05 00:29:27	1.2
@@ -24,6 +24,7 @@
         refbuf_t *headbuf[10];
 } vstate_t;
 
+void format_vorbis_free_plugin(format_plugin_t *self);
 refbuf_t *format_vorbis_get_buffer(format_plugin_t *self, char *data, unsigned long len);
 refbuf_queue_t *format_vorbis_get_predata(format_plugin_t *self);
 
@@ -33,10 +34,12 @@
         vstate_t *state;
 
         plugin = (format_plugin_t *)malloc(sizeof(format_plugin_t));
+
         plugin->type = FORMAT_TYPE_VORBIS;
         plugin->has_predata = 1;
         plugin->get_buffer = format_vorbis_get_buffer;
         plugin->get_predata = format_vorbis_get_predata;
+	plugin->free_plugin = format_vorbis_free_plugin;
 
         state = (vstate_t *)calloc(1, sizeof(vstate_t));
         ogg_sync_init(&state->oy);
@@ -44,6 +47,29 @@
         plugin->_state = (void *)state;
 
         return plugin;
+}
+
+void format_vorbis_free_plugin(format_plugin_t *self)
+{
+	int i;
+	vstate_t *state = (vstate_t *)self->_state;
+
+	/* free memory associated with this plugin instance */
+
+	/* free state memory */
+	ogg_sync_clear(&state->oy);
+	
+	for (i = 0; i < 10; i++) {
+		if (state->headbuf[i]) {
+			refbuf_release(state->headbuf[i]);
+			state->headbuf[i] = NULL;
+		}
+	}
+
+	free(state);
+
+	/* free the plugin instance */
+	free(self);
 }
 
 refbuf_t *format_vorbis_get_buffer(format_plugin_t *self, char *data, unsigned long len)

1.4       +1 -0      icecast/src/source.c

Index: source.c
===================================================================
RCS file: /usr/local/cvsroot/icecast/src/source.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- source.c	2001/10/21 10:07:51	1.3
+++ source.c	2002/01/05 00:29:27	1.4
@@ -90,6 +90,7 @@
         httpp_destroy(source->parser);
         avl_tree_free(source->pending_tree, _free_client);
         avl_tree_free(source->client_tree, _free_client);
+	source->format->free_plugin(source->format);
         free(source);
 
         return 1;

--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the commits mailing list