summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthieu Herrb <matthieu@herrb.eu>2015-11-07 18:51:17 +0100
committerMatthieu Herrb <matthieu@herrb.eu>2015-11-07 18:51:17 +0100
commit1be2bc04b11834db2c1dd8587fd725ef9106016d (patch)
treed42b5f079614736991338366572a62b4e03f3b23
parent7755c564b9b7f306fd8d47f35f37ae06e6ea0acd (diff)
parentc5abcb619eb0b01f074fd9acb9128f19af774834 (diff)
Merge remote-tracking branch 'origin/master' into obsd
-rw-r--r--src/menus.c32
-rw-r--r--src/util.c8
-rw-r--r--src/util.h2
3 files changed, 23 insertions, 19 deletions
diff --git a/src/menus.c b/src/menus.c
index a390444..8aa99c7 100644
--- a/src/menus.c
+++ b/src/menus.c
@@ -2020,7 +2020,7 @@ ExecuteFunction(int func, const char *action, Window w, TwmWindow *tmp_win,
"%s: unable to open cut file \"%s\"\n",
ProgramName, tmp);
}
- if (ptr != tmp) free (ptr);
+ free (ptr);
}
} else {
XFree(ptr);
@@ -2171,21 +2171,25 @@ ExecuteFunction(int func, const char *action, Window w, TwmWindow *tmp_win,
case F_FILE:
ptr = ExpandFilename(action);
- fd = open(ptr, O_RDONLY);
- if (fd >= 0)
- {
- count = read(fd, buff, MAX_FILE_SIZE - 1);
- if (count > 0)
- XStoreBytes(dpy, buff, count);
+ if (ptr) {
+ fd = open(ptr, O_RDONLY);
+ if (fd >= 0)
+ {
+ count = read(fd, buff, MAX_FILE_SIZE - 1);
+ if (count > 0)
+ XStoreBytes(dpy, buff, count);
- close(fd);
- }
- else
- {
- fprintf (stderr, "%s: unable to open file \"%s\"\n",
- ProgramName, ptr);
+ close(fd);
+ }
+ else
+ {
+ fprintf (stderr, "%s: unable to open file \"%s\"\n",
+ ProgramName, ptr);
+ }
+ free(ptr);
+ } else {
+ fprintf (stderr, "%s: error expanding filename\n", ProgramName);
}
- if (ptr != action) free(ptr);
break;
case F_REFRESH:
diff --git a/src/util.c b/src/util.c
index 986ff79..fc5bf7d 100644
--- a/src/util.c
+++ b/src/util.c
@@ -256,11 +256,11 @@ Zoom(Window wf, Window wt)
* \param name the filename to expand
*/
char *
-ExpandFilename(char *name)
+ExpandFilename(const char *name)
{
char *newname;
- if (name[0] != '~') return name;
+ if (name[0] != '~') return strdup(name);
asprintf(&newname, "%s/%s", Home, &name[1]);
if (!newname) {
@@ -348,7 +348,7 @@ FindBitmap (const char *name, unsigned *widthp, unsigned *heightp)
pm = XmuLocateBitmapFile (ScreenOfDisplay(dpy, Scr->screen), bigname, NULL,
0, (int *)widthp, (int *)heightp, &HotX, &HotY);
if (pm == None && Scr->IconDirectory && bigname[0] != '/') {
- if (bigname != name) free (bigname);
+ free (bigname);
/*
* Attempt to find icon in old IconDirectory (now obsolete)
*/
@@ -364,7 +364,7 @@ FindBitmap (const char *name, unsigned *widthp, unsigned *heightp)
pm = None;
}
}
- if (bigname != name) free (bigname);
+ free (bigname);
if (pm == None) {
fprintf (stderr, "%s: unable to find bitmap \"%s\"\n",
ProgramName, name);
diff --git a/src/util.h b/src/util.h
index 7f4527c..4b2d3a8 100644
--- a/src/util.h
+++ b/src/util.h
@@ -64,7 +64,7 @@ in this Software without prior written authorization from The Open Group.
extern void MoveOutline ( Window root, int x, int y, int width, int height,
int bw, int th );
extern void Zoom ( Window wf, Window wt );
-extern char * ExpandFilename ( char *name );
+extern char * ExpandFilename ( const char *name );
extern void GetUnknownIcon ( const char *name );
extern Pixmap FindBitmap ( const char *name, unsigned int *widthp,
unsigned int *heightp );