#! /bin/sh /usr/share/dpatch/dpatch-run
## 02_asprintf.dpatch by Tobias Grimm <tg@e-tobi.net>
##
## All lines beginning with `## DP:' are a description of the patch.
## DP: Fixes wrong usage of asprintf and correctly free's memory allocated by it.

@DPATCH@
diff -urNad --exclude=CVS --exclude=.svn ./submenu-setup.c /tmp/dpep-work.ho7VxE/vdr-plugin-submenu-0.0.2/submenu-setup.c
--- ./submenu-setup.c	2005-02-03 15:35:49.000000000 +0100
+++ /tmp/dpep-work.ho7VxE/vdr-plugin-submenu-0.0.2/submenu-setup.c	2005-08-24 00:37:43.000000000 +0200
@@ -245,19 +245,25 @@
 void cSubMenuSetup::DrawSubMenu(int level)
 {
 	curLevel++;
-	char *line;
+	char *line, *tmp;
 	for(int i=0;i<SMSetup.Arbo.MaxItem[level];i++)
 	{
 		asprintf(&line,"%s","");
 		for (int z=0;z<curLevel*5;z++)
 		{
-			asprintf(&line,"%s ",line);
+			tmp = line;
+			asprintf(&line,"%s ",tmp);
+			free(tmp);
 		}
 		if (SMSetup.subMenuItem[SMSetup.Arbo.Index[level][i]].kindOfItem!=0)
 		{
-			asprintf(&line,"%s+",line);
+			tmp = line;
+			asprintf(&line,"%s+",tmp);
+			free(tmp);
 		}
-		asprintf(&line,"%s%s",line,tr(SMSetup.subMenuItem[SMSetup.Arbo.Index[level][i]].name));
+		tmp = line;
+		asprintf(&line,"%s%s",tmp,tr(SMSetup.subMenuItem[SMSetup.Arbo.Index[level][i]].name));
+		free(tmp);
 		Add (new cOsdItem(line),true);
 		SMSetup.Arbo.CurrentIndex[Current()]=SMSetup.Arbo.Index[level][i];
 		if (SMSetup.subMenuItem[SMSetup.Arbo.Index[level][i]].kindOfItem!=0)
@@ -265,23 +271,26 @@
 		   DrawSubMenu(SMSetup.subMenuItem[SMSetup.Arbo.Index[level][i]].kindOfItem);
 		   curLevel--;
 		}
+		free(line);
 	}
-	delete line;
 }
 
 void cSubMenuSetup::DrawMenu(void)
 {
 	int cur=Current();
 	Clear();
-	char *line;
+	char *line, *tmp;
 	for (int j=0;j<SMSetup.Arbo.MaxItem[0];j++)
 	{
 		asprintf(&line,"%s"," ");
 		if (SMSetup.subMenuItem[SMSetup.Arbo.Index[0][j]].kindOfItem!=0)
 		{
+			free(line);
 			asprintf(&line,"+");
 		}
-		asprintf(&line,"%s%s",line,tr(SMSetup.subMenuItem[SMSetup.Arbo.Index[0][j]].name));
+		tmp = line; 
+		asprintf(&line,"%s%s",tmp,tr(SMSetup.subMenuItem[SMSetup.Arbo.Index[0][j]].name));
+		free(tmp);
 		Add (new cOsdItem(line),true);
 		SMSetup.Arbo.CurrentIndex[Current()]=SMSetup.Arbo.Index[0][j];
 		if (SMSetup.subMenuItem[SMSetup.Arbo.Index[0][j]].kindOfItem!=0)
@@ -289,10 +298,10 @@
 			DrawSubMenu(SMSetup.subMenuItem[SMSetup.Arbo.Index[0][j]].kindOfItem);
 			curLevel--;
 		}
+		free(line);
 	}
 	SetCurrent(Get(cur));
 	Display();
-	delete line;
 }
 
 
