openbsd-ports/x11/xsel/patches/patch-xsel_c
sthen 67285321a2 add patches from patrick keshishian:
- fix issue where NUM_TARGETS in main() is incremented one too many times.
- plug memory leak in handle_targets() where copy of supported_targets created
to be passed to change_property() -> XChangeProperty() but not free()-ed.
2014-07-07 08:25:16 +00:00

53 lines
1.5 KiB
Plaintext

$OpenBSD: patch-xsel_c,v 1.2 2014/07/07 08:25:16 sthen Exp $
- Format "32" properties use "long", not "int", even on LP64 platforms.
- ensure NUM_TARGETS does not exceed MAX_NUM_TARGETS.
- plug a memory leak in handle_targets()
--- xsel.c.orig Mon Jun 30 00:10:19 2014
+++ xsel.c Mon Jun 30 00:20:50 2014
@@ -15,6 +15,7 @@
#include "config.h"
#endif
+#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
@@ -1300,14 +1301,16 @@ handle_targets (Display * display, Window requestor, A
Atom selection, Time time, MultTrack * mparent)
{
Atom * targets_cpy;
+ HandleResult r;
targets_cpy = malloc (sizeof (supported_targets));
memcpy (targets_cpy, supported_targets, sizeof (supported_targets));
- return
- change_property (display, requestor, property, XA_ATOM, 32,
+ r = change_property (display, requestor, property, XA_ATOM, 32,
PropModeReplace, (unsigned char *)targets_cpy,
NUM_TARGETS, selection, time, mparent);
+ free(targets_cpy);
+ return r;
}
/*
@@ -2078,7 +2081,6 @@ main(int argc, char *argv[])
/* Get the NULL atom */
null_atom = XInternAtom (display, "NULL", False);
- NUM_TARGETS++;
/* Get the TEXT atom */
text_atom = XInternAtom (display, "TEXT", False);
@@ -2096,6 +2098,8 @@ main(int argc, char *argv[])
supported_targets[s++] = XA_STRING;
NUM_TARGETS++;
+
+ assert(NUM_TARGETS <= MAX_NUM_TARGETS);
/* Get the COMPOUND_TEXT atom.
* NB. We do not currently serve COMPOUND_TEXT; we can retrieve it but