Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix some segfaults #165

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions Makefile
Expand Up @@ -85,6 +85,10 @@ CFG += -DCOMPTON_VERSION="\"$(COMPTON_VERSION)\""

LDFLAGS ?= -Wl,-O1 -Wl,--as-needed

ifneq "$(DEBUG)" ""
LDFLAGS += -g
endif

ifeq "$(CFG_DEV)" ""
CFLAGS ?= -DNDEBUG -O2 -D_FORTIFY_SOURCE=2
else
Expand Down
3 changes: 0 additions & 3 deletions man/compton.1.asciidoc
Expand Up @@ -86,9 +86,6 @@ OPTIONS
*--config* 'PATH'::
Look for configuration file at the path. See *CONFIGURATION FILES* section below for where compton looks for a configuration file by default.

*--write-pid-path* 'PATH'::
Write process ID to a file.

*--shadow-red* 'VALUE'::
Red color value of shadow (0.0 - 1.0, defaults to 0).

Expand Down
77 changes: 21 additions & 56 deletions src/common.h
Expand Up @@ -60,10 +60,6 @@
#error Cannot enable c2 debugging without c2 support.
#endif

#ifndef COMPTON_VERSION
#define COMPTON_VERSION "unknown"
#endif

// === Includes ===

// For some special functions
Expand Down Expand Up @@ -136,12 +132,6 @@
#define MSTR_(s) #s
#define MSTR(s) MSTR_(s)

/// @brief Wrapper for gcc branch prediction builtin, for likely branch.
#define likely(x) __builtin_expect(!!(x), 1)

/// @brief Wrapper for gcc branch prediction builtin, for unlikely branch.
#define unlikely(x) __builtin_expect(!!(x), 0)

/// Print out an error message.
#define printf_err(format, ...) \
fprintf(stderr, format "\n", ## __VA_ARGS__)
Expand Down Expand Up @@ -323,7 +313,6 @@ typedef enum {
enum backend {
BKEND_XRENDER,
BKEND_GLX,
BKEND_XR_GLX_HYBRID,
NUM_BKEND,
};

Expand Down Expand Up @@ -442,13 +431,9 @@ typedef struct {
// === General ===
/// The configuration file we used.
char *config_file;
/// Path to write PID to.
char *write_pid_path;
/// The display name we used. NULL means we are using the value of the
/// <code>DISPLAY</code> environment variable.
char *display;
/// Safe representation of display name.
char *display_repr;
/// The backend in use.
enum backend backend;
/// Whether to avoid using stencil buffer under GLX backend. Might be
Expand Down Expand Up @@ -646,7 +631,7 @@ typedef struct {
/// A Picture acting as the painting target.
Picture tgt_picture;
/// Temporary buffer to paint to before sending to display.
paint_t tgt_buffer;
Picture tgt_buffer;
/// DBE back buffer for root window. Used in DBE painting mode.
XdbeBackBuffer root_dbe;
/// Window ID of the window we register as a symbol.
Expand Down Expand Up @@ -1001,7 +986,7 @@ typedef struct _win {
/// _NET_WM_OPACITY value
opacity_t opacity_prop_client;
/// Last window opacity value we set.
opacity_t opacity_set;
long opacity_set;

// Fading-related members
/// Do not fade if it's false. Change on window type change.
Expand Down Expand Up @@ -1056,6 +1041,9 @@ typedef struct _win {
/// Textures and FBO background blur use.
glx_blur_cache_t glx_blur_cache;
#endif

/* k8 */
bool dead;
} win;

/// Temporary structure used for communication between
Expand Down Expand Up @@ -1165,15 +1153,6 @@ allocchk_(const char *func_name, void *ptr) {
/// @brief Wrapper of allocchk_().
#define allocchk(ptr) allocchk_(__func__, ptr)

/// @brief Wrapper of malloc().
#define cmalloc(nmemb, type) ((type *) allocchk(malloc((nmemb) * sizeof(type))))

/// @brief Wrapper of calloc().
#define ccalloc(nmemb, type) ((type *) allocchk(calloc((nmemb), sizeof(type))))

/// @brief Wrapper of ealloc().
#define crealloc(ptr, nmemb, type) ((type *) allocchk(realloc((ptr), (nmemb) * sizeof(type))))

/**
* Return whether a struct timeval value is empty.
*/
Expand Down Expand Up @@ -1334,7 +1313,10 @@ print_timestamp(session_t *ps) {
*/
static inline char *
mstrcpy(const char *src) {
char *str = cmalloc(strlen(src) + 1, char);
char *str = malloc(sizeof(char) * (strlen(src) + 1));

if (!str)
printf_errfq(1, "(): Failed to allocate memory.");

strcpy(str, src);

Expand All @@ -1346,7 +1328,10 @@ mstrcpy(const char *src) {
*/
static inline char *
mstrncpy(const char *src, unsigned len) {
char *str = cmalloc(len + 1, char);
char *str = malloc(sizeof(char) * (len + 1));

if (!str)
printf_errfq(1, "(): Failed to allocate memory.");

strncpy(str, src, len);
str[len] = '\0';
Expand All @@ -1359,7 +1344,7 @@ mstrncpy(const char *src, unsigned len) {
*/
static inline char *
mstrjoin(const char *src1, const char *src2) {
char *str = cmalloc(strlen(src1) + strlen(src2) + 1, char);
char *str = malloc(sizeof(char) * (strlen(src1) + strlen(src2) + 1));

strcpy(str, src1);
strcat(str, src2);
Expand All @@ -1372,8 +1357,8 @@ mstrjoin(const char *src1, const char *src2) {
*/
static inline char *
mstrjoin3(const char *src1, const char *src2, const char *src3) {
char *str = cmalloc(strlen(src1) + strlen(src2)
+ strlen(src3) + 1, char);
char *str = malloc(sizeof(char) * (strlen(src1) + strlen(src2)
+ strlen(src3) + 1));

strcpy(str, src1);
strcat(str, src2);
Expand All @@ -1387,8 +1372,7 @@ mstrjoin3(const char *src1, const char *src2, const char *src3) {
*/
static inline void
mstrextend(char **psrc1, const char *src2) {
*psrc1 = crealloc(*psrc1, (*psrc1 ? strlen(*psrc1): 0) + strlen(src2) + 1,
char);
*psrc1 = realloc(*psrc1, (*psrc1 ? strlen(*psrc1): 0) + strlen(src2) + 1);

strcat(*psrc1, src2);
}
Expand Down Expand Up @@ -1687,7 +1671,7 @@ find_win(session_t *ps, Window id) {
win *w;

for (w = ps->list; w; w = w->next) {
if (w->id == id && !w->destroyed)
if (w->id == id && !w->destroyed && !w->dead)
return w;
}

Expand All @@ -1706,32 +1690,13 @@ find_toplevel(session_t *ps, Window id) {
return NULL;

for (win *w = ps->list; w; w = w->next) {
if (w->client_win == id && !w->destroyed)
if (w->client_win == id && !w->destroyed && !w->dead)
return w;
}

return NULL;
}


/**
* Check if current backend uses XRender for rendering.
*/
static inline bool
bkend_use_xrender(session_t *ps) {
return BKEND_XRENDER == ps->o.backend
|| BKEND_XR_GLX_HYBRID == ps->o.backend;
}

/**
* Check if current backend uses GLX.
*/
static inline bool
bkend_use_glx(session_t *ps) {
return BKEND_GLX == ps->o.backend
|| BKEND_XR_GLX_HYBRID == ps->o.backend;
}

/**
* Check if a window is really focused.
*/
Expand Down Expand Up @@ -2046,7 +2011,7 @@ free_texture(session_t *ps, glx_texture_t **pptex) {
static inline void
glx_mark_(session_t *ps, const char *func, XID xid, bool start) {
#ifdef DEBUG_GLX_MARK
if (bkend_use_glx(ps) && ps->glStringMarkerGREMEDY) {
if (BKEND_GLX == ps->o.backend && ps->glStringMarkerGREMEDY) {
if (!func) func = "(unknown)";
const char *postfix = (start ? " (start)": " (end)");
char *str = malloc((strlen(func) + 12 + 2
Expand All @@ -2067,7 +2032,7 @@ glx_mark_(session_t *ps, const char *func, XID xid, bool start) {
static inline void
glx_mark_frame(session_t *ps) {
#ifdef DEBUG_GLX_MARK
if (bkend_use_glx(ps) && ps->glFrameTerminatorGREMEDY)
if (BKEND_GLX == ps->o.backend && ps->glFrameTerminatorGREMEDY)
ps->glFrameTerminatorGREMEDY();
#endif
}
Expand Down