[mw-devel] [Git][arthur/mw][master] Fix memory leak in add_folder

Andrew Price welshbyte at sucs.org
Sat Nov 14 15:08:28 GMT 2015


Andrew Price pushed to branch master at Justin Mitchell / mw


Commits:
152e0a0c by Andrew Price at 2015-11-14T15:07:03Z
Fix memory leak in add_folder

- - - - -


1 changed file:

- src/client/folders.c


Changes:

=====================================
src/client/folders.c
=====================================
--- a/src/client/folders.c
+++ b/src/client/folders.c
@@ -19,58 +19,57 @@
 
 void add_folder(void)
 {
-	struct folder *new;
+	struct folder new;
 	int file;
 	int yes;
 	int folnum = -1;
 	char tmp[11];
 
 	if (nofolders()) create_folder_file();
-	new=(struct folder *)malloc(sizeof(*new));
 	file=openfolderfile(O_RDWR);
 	do{
-		yes=get_folder_entry(file,new);
+		yes=get_folder_entry(file, &new);
 		folnum++;
-	}while (yes && ((new->status)&1));
+	}while (yes && ((new.status)&1));
 	if (!yes)
 	{
 		printf(_("Sorry, no space for a new folder.\n"));
 		return;
 	}
-	if (lseek(file,-(sizeof(*new)),1)<0)
+	if (lseek(file, -(sizeof(new)), SEEK_CUR) < 0)
 	{
 		perror("add_folder (seek)");
 		exit(-1);
 	}
 	printf(_("Create new folder :\n"));
 	printf(_("Folder name (%d chars): "),FOLNAMESIZE);
-	get_str(new->name,FOLNAMESIZE);
-	if (*(new->name)==0) return;
+	get_str(new.name, FOLNAMESIZE);
+	if (new.name[0] == '\0') return;
 	printf(_("Folder topic (%d chars): "),TOPICSIZE);
-	get_str(new->topic,TOPICSIZE);
+	get_str(new.topic,TOPICSIZE);
 	printf(_("Folder status (not in group) (arwRWpm): "));
 	get_str(tmp,10);
-	new->status=folder_stats(tmp,0)|1;
+	new.status = folder_stats(tmp,0)|1;
 	printf(_("Folder status (in group) (arwRWpm): "));
 	get_str(tmp,10);
-	new->g_status=folder_stats(tmp,0)|1;
+	new.g_status = folder_stats(tmp,0)|1;
 	printf(_("Folder groups (12345678): "));
 	get_str(tmp,10);
-	new->groups=folder_groups(tmp,0);
-	new->first=0;
-	new->last=0;
-	printf(_("Creating folder %s - %s\n"),new->name,new->topic);
+	new.groups = folder_groups(tmp,0);
+	new.first = 0;
+	new.last = 0;
+	printf(_("Creating folder %s - %s\n"), new.name, new.topic);
 
 	auto_subscribe(folnum,true);
 	Lock_File(file); /* folder file */
-	if (write(file,new,sizeof(*new))<0)
+	if (write(file, &new, sizeof(new)) <  0)
 	{
 		perror("add_folder");
 		exit(0);
 	}
 	Unlock_File(file);
 	close(file);
-	mwlog("FOLDER(CREATED) %s", new->name);
+	mwlog("FOLDER(CREATED) %s", new.name);
 }
 
 void auto_subscribe(int folnum, int state)



View it on GitLab: https://projects.sucs.org/arthur/mw/commit/152e0a0cf54ee64155c53adec8e7cced0051fee5
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sucs.org/pipermail/mw-devel/attachments/20151114/e3c7873e/attachment.html>


More information about the mw-devel mailing list