wmfsm: Apply further Debian patches.

The individual patches no longer seem to exist, so I submit them together.
According to debian/changelog entries by Arthur Korn <arthur@debian.org>,
these patches include:
* fixed memleak introduced in 0.34-2 with the patch by Timo Benk.
  global char *mp[] was assigned the result of stdup() repeatedly
  without free. My ugly fix is to free it all up at the beginning of
  readFileSystems(). Now I'm a proud Perl coder ... closes: #196057
* memleak news: avoid it if there are more than 9 filesystems too.
* Fixed filesystem name corruption, thanks to Ralf Horstmann and Cristian
  Ionescu-Idbohrn for the patch.
This commit is contained in:
Doug Torrance 2015-01-22 00:22:04 -06:00 committed by Carlos R. Mafra
parent 3eb9307a7b
commit aef6c49d83

View file

@ -38,6 +38,7 @@
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
#include <ctype.h>
#include <string.h> #include <string.h>
#include <X11/X.h> #include <X11/X.h>
#include <X11/xpm.h> #include <X11/xpm.h>
@ -78,7 +79,6 @@
# define STATFS(a,b) statfs(a,b) /* Maybe configure got messed up */ # define STATFS(a,b) statfs(a,b) /* Maybe configure got messed up */
#endif #endif
/* /*
#if defined IRIX64 #if defined IRIX64
# include <sys/types.h> # include <sys/types.h>
@ -228,7 +228,7 @@ main(int argc, char *argv[])
if (numberfs > 4) { if (numberfs > 4) {
for (i = 0, dy = 0; i < numberfs; i++) { for (i = 0, dy = 0; i < numberfs; i++) {
for (j = 0, dx = 0; j < LENMP && j < strlen(mp[i]); j++) { for (j = 0, dx = 0; j < LENMP && (unsigned int)j < strlen(mp[i]); j++) {
k = j + (strlen(mp[i]) > LENMP ? strlen(mp[i]) - LENMP : 0); k = j + (strlen(mp[i]) > LENMP ? strlen(mp[i]) - LENMP : 0);
c = (int) mp[i][k]; c = (int) mp[i][k];
switch (c) { switch (c) {
@ -284,7 +284,7 @@ main(int argc, char *argv[])
} }
else { /*one fs in two lines */ else { /*one fs in two lines */
for (i = 0, dy = 0; i < numberfs; i++) { for (i = 0, dy = 0; i < numberfs; i++) {
for (j = 0, dx = 0; j < 10 && j < strlen(mp[i]); j++) { for (j = 0, dx = 0; j < 10 && (unsigned int)j < strlen(mp[i]); j++) {
c = (int) mp[i][j + (strlen(mp[i]) > 10 ? strlen(mp[i]) - 10 : 0)]; c = (int) mp[i][j + (strlen(mp[i]) > 10 ? strlen(mp[i]) - 10 : 0)];
switch (c) { switch (c) {
case '/': case '/':
@ -337,7 +337,7 @@ main(int argc, char *argv[])
} }
} }
if (numberfs < 9) { if (numberfs < 9) {
for (j = 0, dx = 0, dy = 47; j < 10 && j < strlen(hostname); j++) { for (j = 0, dx = 0, dy = 47; j < 10 && (unsigned int)j < strlen(hostname); j++) {
c = (int) hostname[j]; c = (int) hostname[j];
switch (c) { switch (c) {
case '/': case '/':
@ -394,7 +394,7 @@ void
ParseCMDLine(int argc, char *argv[]) ParseCMDLine(int argc, char *argv[])
{ {
int c, option_index, arg; int c, option_index;
static struct option long_options[] = { static struct option long_options[] = {
{"fire", no_argument, 0, 'f'}, {"fire", no_argument, 0, 'f'},
{"normal", no_argument, 0, 'n'}, {"normal", no_argument, 0, 'n'},
@ -453,6 +453,7 @@ print_usage()
void void
pressEvent(XButtonEvent * xev) pressEvent(XButtonEvent * xev)
{ {
(void)xev;
ForceUpdate = 1; ForceUpdate = 1;
return; return;
} }
@ -460,6 +461,14 @@ pressEvent(XButtonEvent * xev)
void void
readFileSystems() readFileSystems()
{ {
/* Wipe mp[] */
int i;
for (i = 0; i < 100; i++)
if (mp[i]) {
free(mp[i]);
mp[i]=0;
}
/* Look for the goods between #if defined(__OpenBSD__) -- tschroed */ /* Look for the goods between #if defined(__OpenBSD__) -- tschroed */
#if defined(__OpenBSD__) || defined(__FreeBSD__) #if defined(__OpenBSD__) || defined(__FreeBSD__)
#define MAXMOUNT 32 #define MAXMOUNT 32
@ -517,6 +526,7 @@ readFileSystems()
1 1
#endif #endif
) { ) {
if (mp[numberfs]) free(mp[numberfs]);
mp[numberfs++] = strdup(mountPoint); mp[numberfs++] = strdup(mountPoint);
} }
} }
@ -532,7 +542,7 @@ excludeFileSystems()
char confFileName[255]; char confFileName[255];
char workString[255]; char workString[255];
int i, j, exnumberfs = 0; int i, j, exnumberfs = 0;
int start = 0, excluded, finalnumberfs = 0; int excluded, finalnumberfs = 0;
char *mount_points[100]; char *mount_points[100];
FILE *confFile; FILE *confFile;
int include = -1; int include = -1;
@ -569,11 +579,11 @@ excludeFileSystems()
} }
else { else {
numberfs = numberfs > 9 ? 9 : numberfs; numberfs = numberfs > 9 ? 9 : numberfs;
return; goto CLEANUP;
} }
if (!exnumberfs) { if (!exnumberfs) {
numberfs = numberfs > 9 ? 9 : numberfs; numberfs = numberfs > 9 ? 9 : numberfs;
return; goto CLEANUP;
} }
excluded = 0; excluded = 0;
for (i = 0; i < numberfs; i++) { for (i = 0; i < numberfs; i++) {
@ -584,13 +594,22 @@ excludeFileSystems()
included = 1; included = 1;
} }
} }
if ((!excluded && !include) || (included && include)) if ((!excluded && !include) || (included && include)) {
mp[finalnumberfs++] = strdup(mp[i]); if (finalnumberfs == i) {
finalnumberfs++;
} else {
if (mp[finalnumberfs]) free(mp[finalnumberfs]);
mp[finalnumberfs++] = strdup(mp[i]);
}
}
included = excluded = 0; included = excluded = 0;
} }
for (j = 0; j < exnumberfs; j++)
free(mount_points[j]);
for (j = finalnumberfs; j < numberfs; j++)
free(mp[j]);
numberfs = finalnumberfs > 9 ? 9 : finalnumberfs; numberfs = finalnumberfs > 9 ? 9 : finalnumberfs;
CLEANUP:
for (j = 0; j < exnumberfs; j++)
if (mount_points[j]) {
free(mount_points[j]);
mount_points[j]=0;
}
} }