Handle alloc failures.
This commit is contained in:
parent
291bae1e44
commit
7c0ba89197
6
main.c
6
main.c
@ -937,6 +937,12 @@ static int load_config(char *path, struct swaylock_state *state,
|
|||||||
|
|
||||||
swaylock_log(LOG_DEBUG, "Config Line #%d: %s", line_number, line);
|
swaylock_log(LOG_DEBUG, "Config Line #%d: %s", line_number, line);
|
||||||
char *flag = malloc(nread + 3);
|
char *flag = malloc(nread + 3);
|
||||||
|
if (flag == NULL) {
|
||||||
|
free(line);
|
||||||
|
free(config);
|
||||||
|
swaylock_log(LOG_ERROR, "Failed to allocate memory");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
sprintf(flag, "--%s", line);
|
sprintf(flag, "--%s", line);
|
||||||
char *argv[] = {"swaylock", flag};
|
char *argv[] = {"swaylock", flag};
|
||||||
result = parse_options(2, argv, state, line_mode, NULL);
|
result = parse_options(2, argv, state, line_mode, NULL);
|
||||||
|
8
pango.c
8
pango.c
@ -94,6 +94,10 @@ PangoLayout *get_pango_layout(cairo_t *cairo, const char *font,
|
|||||||
void get_text_size(cairo_t *cairo, const char *font, int *width, int *height,
|
void get_text_size(cairo_t *cairo, const char *font, int *width, int *height,
|
||||||
int *baseline, double scale, bool markup, const char *fmt, ...) {
|
int *baseline, double scale, bool markup, const char *fmt, ...) {
|
||||||
char *buf = malloc(max_chars);
|
char *buf = malloc(max_chars);
|
||||||
|
if (buf == NULL) {
|
||||||
|
swaylock_log(LOG_ERROR, "Failed to allocate memory");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, fmt);
|
va_start(args, fmt);
|
||||||
@ -116,6 +120,10 @@ void get_text_size(cairo_t *cairo, const char *font, int *width, int *height,
|
|||||||
void pango_printf(cairo_t *cairo, const char *font,
|
void pango_printf(cairo_t *cairo, const char *font,
|
||||||
double scale, bool markup, const char *fmt, ...) {
|
double scale, bool markup, const char *fmt, ...) {
|
||||||
char *buf = malloc(max_chars);
|
char *buf = malloc(max_chars);
|
||||||
|
if (buf == NULL) {
|
||||||
|
swaylock_log(LOG_ERROR, "Failed to allocate memory");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, fmt);
|
va_start(args, fmt);
|
||||||
|
Loading…
Reference in New Issue
Block a user