Hi

I audited a few callweaver applications this weekend and found they leak
memory under certain conditions (typically errors or end of call). I'm
sending patches for app_dtmftotext, app_echo, app_record, app_pipe and
app_t38gateway. No, I didn't check them all, and yes the fact so many
leak memory is concerning.

Also, can I please get some feedback on the post dial delay patch I
posted about a week ago?

Bye
Damjan


Index: app_dtmftotext.c
===================================================================
--- app_dtmftotext.c	(revision 4317)
+++ app_dtmftotext.c	(working copy)
@@ -283,6 +283,7 @@
 					if (opbx_write(chan, &myf.f) < 0)
                     {
 						res = -1;
+						opbx_fr_free(f);
 						break;
 					}
 					if (res < needed)
@@ -290,6 +291,7 @@
                         // last frame
 						opbx_log(LOG_DEBUG, "Last frame\n");
 						res = 0;
+						opbx_fr_free(f);
 						break;
 					}
 				}
Index: app_dtmftotext.c
===================================================================
--- app_dtmftotext.c	(revision 4370)
+++ app_dtmftotext.c	(working copy)
@@ -278,6 +278,7 @@
 					if (opbx_write(chan, &myf.f) < 0)
                     {
 						res = -1;
+						opbx_fr_free(f);
 						break;
 					}
 					if (res < needed)
@@ -285,6 +286,7 @@
                         // last frame
 						opbx_log(OPBX_LOG_DEBUG, "Last frame\n");
 						res = 0;
+						opbx_fr_free(f);
 						break;
 					}
 				}
Index: apps/app_echo.c
===================================================================
--- apps/app_echo.c	(revision 4317)
+++ apps/app_echo.c	(working copy)
@@ -58,7 +58,7 @@
 static int echo_exec(struct opbx_channel *chan, int argc, char **argv)
 {
 	struct localuser *u;
-	struct opbx_frame *f;
+	struct opbx_frame *f = NULL;
 	int res = -1;
 
 	if (argc != 0) {
@@ -92,7 +92,10 @@
 					break;
 		}
 		opbx_fr_free(f);
+		f = NULL;
 	}
+	if (f)
+		opbx_fr_free(f);
 
 	LOCAL_USER_REMOVE(u);
 	return res;
Index: apps/app_echo.c
===================================================================
--- apps/app_echo.c	(revision 4370)
+++ apps/app_echo.c	(working copy)
@@ -55,7 +55,7 @@
 static int echo_exec(struct opbx_channel *chan, int argc, char **argv, char *result, size_t result_max)
 {
 	struct localuser *u;
-	struct opbx_frame *f;
+	struct opbx_frame *f = NULL;
 	int res = -1;
 
 	if (argc != 0)
@@ -87,7 +87,10 @@
 					break;
 		}
 		opbx_fr_free(f);
+		f = NULL;
 	}
+	if (f)
+		opbx_fr_free(f);
 
 	LOCAL_USER_REMOVE(u);
 	return res;
Index: apps/app_pipe.c
===================================================================
--- apps/app_pipe.c	(revision 4317)
+++ apps/app_pipe.c	(working copy)
@@ -196,6 +196,7 @@
 						if (res < 0) {
 							if (errno != EAGAIN) {
 								opbx_log(LOG_WARNING, "Write failed to pipe: %s\n", strerror(errno));
+								opbx_fr_free(f);
 								res = -1;
 								break;
 							}
Index: apps/app_pipe.c
===================================================================
--- apps/app_pipe.c	(revision 4370)
+++ apps/app_pipe.c	(working copy)
@@ -191,6 +191,7 @@
 						if (res < 0) {
 							if (errno != EAGAIN) {
 								opbx_log(OPBX_LOG_WARNING, "Write failed to pipe: %s\n", strerror(errno));
+								opbx_fr_free(f);
 								res = -1;
 								break;
 							}
Index: apps/app_record.c
===================================================================
--- apps/app_record.c	(revision 4317)
+++ apps/app_record.c	(working copy)
@@ -274,6 +274,7 @@
 					
 					if (res) {
 						opbx_log(LOG_WARNING, "Problem writing frame\n");
+						opbx_fr_free(f);
 						break;
 					}
 					
@@ -298,6 +299,7 @@
 					
 					if (res) {
 						opbx_log(LOG_WARNING, "Problem writing frame\n");
+						opbx_fr_free(f);
 						break;
 					}
 				}
Index: apps/app_record.c
===================================================================
--- apps/app_record.c	(revision 4370)
+++ apps/app_record.c	(working copy)
@@ -269,6 +269,7 @@
 					
 					if (res) {
 						opbx_log(OPBX_LOG_WARNING, "Problem writing frame\n");
+						opbx_fr_free(fr);
 						break;
 					}
 					
@@ -293,6 +294,7 @@
 					
 					if (res) {
 						opbx_log(OPBX_LOG_WARNING, "Problem writing frame\n");
+						opbx_fr_free(f);
 						break;
 					}
 				}
Index: app_t38gateway.c
===================================================================
--- app_t38gateway.c	(revision 4317)
+++ app_t38gateway.c	(working copy)
@@ -357,7 +357,10 @@
                 if ((f = opbx_read(active)))
                 {
                     if (t38_gateway_rx(&t38_state, f->data, f->samples))
+                    {
+                        clean_frame(f);
                         break;
+                    }
 
                     samples = (f->samples <= MAX_BLOCK_SIZE)  ?  f->samples  :  MAX_BLOCK_SIZE;
 
@@ -371,6 +374,7 @@
                         if (opbx_write(channels[1], &outf) < 0)
                         {
                             opbx_log(LOG_WARNING, "Unable to write frame to channel; %s\n", strerror(errno));
+                            clean_frame(f);
                             break;
                         }
                     }
Index: app_t38gateway.c
===================================================================
--- app_t38gateway.c	(revision 4370)
+++ app_t38gateway.c	(working copy)
@@ -355,7 +355,10 @@
                 if ((f = opbx_read(active)))
                 {
                     if (t38_gateway_rx(&t38_state, f->data, f->samples))
+                    {
+                        clean_frame(f);
                         break;
+                    }
 
                     samples = (f->samples <= MAX_BLOCK_SIZE)  ?  f->samples  :  MAX_BLOCK_SIZE;
 
@@ -369,6 +372,7 @@
                         if (opbx_write(channels[1], &outf) < 0)
                         {
                             opbx_log(OPBX_LOG_WARNING, "Unable to write frame to channel; %s\n", strerror(errno));
+                            clean_frame(f);
                             break;
                         }
                     }
_______________________________________________
Callweaver-dev mailing list
[email protected]
http://lists.callweaver.org/mailman/listinfo/callweaver-dev

Reply via email to