Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix buffer overflow causing heap corruption #62

Open
wants to merge 2 commits into from

1 participant

@lano1106

in src/hook/alsa.c: Is allocating len bytes for device name contained
in '-a' option values. Last char index is len-1 and code NULL terminate
the string one byte after the end of the array.

I have documented the possible effect of the buffer overflow here:
http://blog.olivierlanglois.net/index.php/2013/12/11/deadlock_when_using_glc

Micro optimization: I have replaced malloc+memset combo with calloc:
Rationale documented here:
http://blog.olivierlanglois.net/index.php/2013/12/11/malloc_memset_vs_calloc_which_is_better

in src/glc/common/log.c: Make log file stream line buffered (like stderr) to see traces
as they happen.

lano1106 and others added some commits
@lano1106 lano1106 Fix buffer overflow causing heap corruption
in src/hook/alsa.c: Is allocating len bytes for device name contained
in '-a' option values. Last char index is len-1 and code NULL terminate
the string one byte after the end of the array.

I have documented the possible effect of the buffer overflow here:
http://blog.olivierlanglois.net/index.php/2013/12/11/deadlock_when_using_glc

Micro optimization: I have replaced malloc+memset combo with calloc:
Rationale documented here:
http://blog.olivierlanglois.net/index.php/2013/12/11/malloc_memset_vs_calloc_which_is_better

in src/glc/common/log.c: Make log file stream line buffered (like stderr) to see traces
as they happen.
855d214
Olivier Langlois Add missing param.
c623179
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 12, 2013
  1. @lano1106

    Fix buffer overflow causing heap corruption

    lano1106 authored
    in src/hook/alsa.c: Is allocating len bytes for device name contained
    in '-a' option values. Last char index is len-1 and code NULL terminate
    the string one byte after the end of the array.
    
    I have documented the possible effect of the buffer overflow here:
    http://blog.olivierlanglois.net/index.php/2013/12/11/deadlock_when_using_glc
    
    Micro optimization: I have replaced malloc+memset combo with calloc:
    Rationale documented here:
    http://blog.olivierlanglois.net/index.php/2013/12/11/malloc_memset_vs_calloc_which_is_better
    
    in src/glc/common/log.c: Make log file stream line buffered (like stderr) to see traces
    as they happen.
  2. Add missing param.

    Olivier Langlois authored
This page is out of date. Refresh to see the latest.
View
3  src/glc/capture/alsa_capture.c
@@ -72,8 +72,7 @@ int alsa_capture_stop(alsa_capture_t alsa_capture);
int alsa_capture_init(alsa_capture_t *alsa_capture, glc_t *glc)
{
- *alsa_capture = (alsa_capture_t) malloc(sizeof(struct alsa_capture_s));
- memset(*alsa_capture, 0, sizeof(struct alsa_capture_s));
+ *alsa_capture = (alsa_capture_t) calloc(1, sizeof(struct alsa_capture_s));
(*alsa_capture)->glc = glc;
(*alsa_capture)->device = "default";
View
6 src/glc/capture/alsa_hook.c
@@ -105,8 +105,7 @@ glc_audio_format_t pcm_fmt_to_glc_fmt(snd_pcm_format_t pcm_fmt);
int alsa_hook_init(alsa_hook_t *alsa_hook, glc_t *glc)
{
- *alsa_hook = (alsa_hook_t) malloc(sizeof(struct alsa_hook_s));
- memset(*alsa_hook, 0, sizeof(struct alsa_hook_s));
+ *alsa_hook = (alsa_hook_t) calloc(1, sizeof(struct alsa_hook_s));
(*alsa_hook)->glc = glc;
@@ -252,8 +251,7 @@ int alsa_hook_get_stream(alsa_hook_t alsa_hook, snd_pcm_t *pcm, struct alsa_hook
}
if (find == NULL) {
- find = (struct alsa_hook_stream_s *) malloc(sizeof(struct alsa_hook_stream_s));
- memset(find, 0, sizeof(struct alsa_hook_stream_s));
+ find = (struct alsa_hook_stream_s *) calloc(1, sizeof(struct alsa_hook_stream_s));
find->pcm = pcm;
find->id = 0; /* zero until it is initialized */
View
3  src/glc/capture/audio_capture.c
@@ -49,8 +49,7 @@ int audio_capture_write_cfg(audio_capture_t audio_capture);
int audio_capture_init(audio_capture_t *audio_capture, glc_t *glc)
{
- *audio_capture = (audio_capture_t) malloc(sizeof(struct audio_capture_s));
- memset(*audio_capture, 0, sizeof(struct audio_capture_s));
+ *audio_capture = (audio_capture_t) calloc(1, sizeof(struct audio_capture_s));
(*audio_capture)->glc = glc;
View
7 src/glc/capture/gl_capture.c
@@ -142,8 +142,7 @@ int gl_capture_read_pbo(gl_capture_t gl_capture, struct gl_capture_video_stream_
int gl_capture_init(gl_capture_t *gl_capture, glc_t *glc)
{
- *gl_capture = (gl_capture_t) malloc(sizeof(struct gl_capture_s));
- memset(*gl_capture, 0, sizeof(struct gl_capture_s));
+ *gl_capture = (gl_capture_t) calloc(1, sizeof(struct gl_capture_s));
(*gl_capture)->glc = glc;
(*gl_capture)->fps = 1000000 / 30; /* default fps is 30 */
@@ -641,8 +640,8 @@ int gl_capture_get_video_stream(gl_capture_t gl_capture, struct gl_capture_video
pthread_rwlock_unlock(&gl_capture->videolist_lock);
if (fvideo == NULL) {
- fvideo = (struct gl_capture_video_stream_s *) malloc(sizeof(struct gl_capture_video_stream_s));
- memset(fvideo, 0, sizeof(struct gl_capture_video_stream_s));
+ fvideo = (struct gl_capture_video_stream_s *)
+ calloc(1, sizeof(struct gl_capture_video_stream_s));
fvideo->dpy = dpy;
fvideo->drawable = drawable;
View
3  src/glc/common/core.c
@@ -42,8 +42,7 @@ int glc_init(glc_t *glc)
glc->util = NULL;
glc->log = NULL;
- glc->core = (glc_core_t) malloc(sizeof(struct glc_core_s));
- memset(glc->core, 0, sizeof(struct glc_core_s));
+ glc->core = (glc_core_t) calloc(1, sizeof(struct glc_core_s));
gettimeofday(&glc->core->init_time, NULL);
glc->core->threads_hint = sysconf(_SC_NPROCESSORS_ONLN);
View
6 src/glc/common/log.c
@@ -32,8 +32,7 @@ void glc_log_write_prefix(glc_t *glc, FILE *stream, int level, const char *modul
int glc_log_init(glc_t *glc)
{
- glc->log = (glc_log_t) malloc(sizeof(struct glc_log_s));
- memset(glc->log, 0, sizeof(struct glc_log_s));
+ glc->log = (glc_log_t) calloc(1, sizeof(struct glc_log_s));
pthread_mutex_init(&glc->log->log_mutex, NULL);
glc->log->default_stream = stderr;
@@ -56,6 +55,9 @@ int glc_log_open_file(glc_t *glc, const char *filename)
if (!stream)
return errno;
+ /* line buffered like stderr */
+ setvbuf( stream, NULL, _IOLBF, 0 );
+
if ((ret = glc_log_set_stream(glc, stream))) {
fclose(stream);
return ret;
View
9 src/glc/common/state.c
@@ -51,8 +51,7 @@ struct glc_state_s {
int glc_state_init(glc_t *glc)
{
glc->state_flags = 0;
- glc->state = (glc_state_t) malloc(sizeof(struct glc_state_s));
- memset(glc->state, 0, sizeof(struct glc_state_s));
+ glc->state = (glc_state_t) calloc(1, sizeof(struct glc_state_s));
pthread_rwlock_init(&glc->state->state_rwlock, NULL);
pthread_rwlock_init(&glc->state->time_rwlock, NULL);
@@ -97,8 +96,7 @@ int glc_state_destroy(glc_t *glc)
int glc_state_video_new(glc_t *glc, glc_stream_id_t *id,
glc_state_video_t *video)
{
- *video = (glc_state_video_t) malloc(sizeof(struct glc_state_video_s));
- memset(*video, 0, sizeof(struct glc_state_video_s));
+ *video = (glc_state_video_t) calloc(1, sizeof(struct glc_state_video_s));
pthread_rwlock_wrlock(&glc->state->video_rwlock);
(*video)->id = ++glc->state->video_count;
@@ -113,8 +111,7 @@ int glc_state_video_new(glc_t *glc, glc_stream_id_t *id,
int glc_state_audio_new(glc_t *glc, glc_stream_id_t *id,
glc_state_audio_t *audio)
{
- *audio = (glc_state_audio_t) malloc(sizeof(struct glc_state_audio_s));
- memset(*audio, 0, sizeof(struct glc_state_audio_s));
+ *audio = (glc_state_audio_t) calloc(1, sizeof(struct glc_state_audio_s));
pthread_rwlock_wrlock(&glc->state->audio_rwlock);
(*audio)->id = ++glc->state->audio_count;
View
4 src/glc/common/thread.c
@@ -54,9 +54,9 @@ int glc_thread_create(glc_t *glc, glc_thread_t *thread, ps_buffer_t *from, ps_bu
if (thread->threads < 1)
return EINVAL;
- if (!(private = (struct glc_thread_private_s *) malloc(sizeof(struct glc_thread_private_s))))
+ if (!(private = (struct glc_thread_private_s *)
+ calloc(1, sizeof(struct glc_thread_private_s))))
return ENOMEM;
- memset(private, 0, sizeof(struct glc_thread_private_s));
thread->priv = private;
private->glc = glc;
View
6 src/glc/common/util.c
@@ -53,8 +53,7 @@ int glc_util_utc_date(glc_t *glc, char **date, u_int32_t *date_size);
int glc_util_init(glc_t *glc)
{
- glc->util = (glc_util_t) malloc(sizeof(struct glc_util_s));
- memset(glc->util, 0, sizeof(struct glc_util_s));
+ glc->util = (glc_util_t) calloc(1, sizeof(struct glc_util_s));
glc->util->fps = 30;
glc->util->pid = getpid();
@@ -77,8 +76,7 @@ int glc_util_info_fps(glc_t *glc, double fps)
int glc_util_info_create(glc_t *glc, glc_stream_info_t **stream_info,
char **info_name, char **info_date)
{
- *stream_info = (glc_stream_info_t *) malloc(sizeof(glc_stream_info_t));
- memset(*stream_info, 0, sizeof(glc_stream_info_t));
+ *stream_info = (glc_stream_info_t *) calloc(1, sizeof(glc_stream_info_t));
(*stream_info)->signature = GLC_SIGNATURE;
(*stream_info)->version = GLC_STREAM_VERSION;
View
6 src/glc/core/color.c
@@ -102,8 +102,7 @@ __inline__ unsigned char color_clamp(int val)
int color_init(color_t *color, glc_t *glc)
{
- *color = malloc(sizeof(struct color_s));
- memset(*color, 0, sizeof(struct color_s));
+ *color = calloc(1, sizeof(struct color_s));
(*color)->glc = glc;
@@ -246,8 +245,7 @@ void color_get_video_stream(color_t color, glc_stream_id_t id,
}
if (*video == NULL) {
- *video = malloc(sizeof(struct color_video_stream_s));
- memset(*video, 0, sizeof(struct color_video_stream_s));
+ *video = calloc(1, sizeof(struct color_video_stream_s));
(*video)->next = color->video;
color->video = *video;
View
6 src/glc/core/copy.c
@@ -49,8 +49,7 @@ void *copy_thread(void *argptr);
int copy_init(copy_t *copy, glc_t *glc)
{
- *copy = (copy_t) malloc(sizeof(struct copy_s));
- memset(*copy, 0, sizeof(struct copy_s));
+ *copy = (copy_t) calloc(1, sizeof(struct copy_s));
(*copy)->glc = glc;
@@ -75,8 +74,7 @@ int copy_destroy(copy_t copy)
int copy_add(copy_t copy, ps_buffer_t *target, glc_message_type_t type)
{
- struct copy_target_s *newtarget = malloc(sizeof(struct copy_target_s));
- memset(newtarget, 0, sizeof(struct copy_target_s));
+ struct copy_target_s *newtarget = calloc(1, sizeof(struct copy_target_s));
newtarget->buffer = target;
newtarget->type = type;
View
3  src/glc/core/file.c
@@ -61,8 +61,7 @@ int file_write_state_callback(glc_message_header_t *header, void *message, size_
int file_init(file_t *file, glc_t *glc)
{
- *file = malloc(sizeof(struct file_s));
- memset(*file, 0, sizeof(struct file_s));
+ *file = calloc(1, sizeof(struct file_s));
(*file)->glc = glc;
(*file)->fd = -1;
View
10 src/glc/core/info.c
@@ -88,8 +88,7 @@ void print_bytes(FILE *stream, size_t bytes);
int info_init(info_t *info, glc_t *glc)
{
- *info = (info_t) malloc(sizeof(struct info_s));
- memset(*info, 0, sizeof(struct info_s));
+ *info = (info_t) calloc(1, sizeof(struct info_s));
(*info)->glc = glc;
(*info)->video_list = NULL;
@@ -231,8 +230,8 @@ int info_get_video_stream(info_t info, struct info_video_stream_s **video, glc_s
}
if (fvideo == NULL) {
- fvideo = (struct info_video_stream_s *) malloc(sizeof(struct info_video_stream_s));
- memset(fvideo, 0, sizeof(struct info_video_stream_s));
+ fvideo = (struct info_video_stream_s *)
+ calloc(1, sizeof(struct info_video_stream_s));
fvideo->next = info->video_list;
info->video_list = fvideo;
@@ -256,8 +255,7 @@ int info_get_audio_stream(info_t info, struct info_audio_stream_s **audio,
}
if (*audio == NULL) {
- *audio = malloc(sizeof(struct info_audio_stream_s));
- memset(*audio, 0, sizeof(struct info_audio_stream_s));
+ *audio = calloc(1, sizeof(struct info_audio_stream_s));
(*audio)->next = info->audio_list;
info->audio_list = *audio;
View
6 src/glc/core/pack.c
@@ -77,8 +77,7 @@ void unpack_finish_callback(void *ptr, int err);
int pack_init(pack_t *pack, glc_t *glc)
{
- *pack = (pack_t) malloc(sizeof(struct pack_s));
- memset(*pack, 0, sizeof(struct pack_s));
+ *pack = (pack_t) calloc(1, sizeof(struct pack_s));
(*pack)->glc = glc;
(*pack)->compress_min = 1024;
@@ -351,8 +350,7 @@ int pack_lzjb_write_callback(glc_thread_state_t *state)
int unpack_init(unpack_t *unpack, glc_t *glc)
{
- *unpack = (unpack_t) malloc(sizeof(struct unpack_s));
- memset(*unpack, 0, sizeof(struct unpack_s));
+ *unpack = (unpack_t) calloc(1, sizeof(struct unpack_s));
(*unpack)->glc = glc;
View
6 src/glc/core/rgb.c
@@ -116,8 +116,7 @@ int rgb_convert_lookup(rgb_t rgb, struct rgb_video_stream_s *ctx,
int rgb_init(rgb_t *rgb, glc_t *glc)
{
- *rgb = (rgb_t) malloc(sizeof(struct rgb_s));
- memset(*rgb, 0, sizeof(struct rgb_s));
+ *rgb = (rgb_t) calloc(1, sizeof(struct rgb_s));
(*rgb)->glc = glc;
@@ -236,8 +235,7 @@ void rgbget_video_stream(rgb_t rgb, glc_stream_id_t id,
}
if (*ctx == NULL) {
- *ctx = malloc(sizeof(struct rgb_video_stream_s));
- memset(*ctx, 0, sizeof(struct rgb_video_stream_s));
+ *ctx = (struct rgb_video_stream_s *) calloc(1, sizeof(struct rgb_video_stream_s));
(*ctx)->next = rgb->ctx;
rgb->ctx = *ctx;
View
7 src/glc/core/scale.c
@@ -92,8 +92,7 @@ void scale_ycbcr_scale(scale_t scale, struct scale_video_stream_s *video,
int scale_init(scale_t *scale, glc_t *glc)
{
- *scale = malloc(sizeof(struct scale_s));
- memset(*scale, 0, sizeof(struct scale_s));
+ *scale = calloc(1, sizeof(struct scale_s));
(*scale)->glc = glc;
@@ -233,8 +232,8 @@ int scale_get_video_stream(scale_t scale, glc_stream_id_t id, struct scale_video
}
if (list == NULL) {
- list = (struct scale_video_stream_s *) malloc(sizeof(struct scale_video_stream_s));
- memset(list, 0, sizeof(struct scale_video_stream_s));
+ list = (struct scale_video_stream_s *)
+ calloc(1, sizeof(struct scale_video_stream_s));
list->next = scale->video;
scale->video = list;
View
10 src/glc/core/tracker.c
@@ -53,9 +53,7 @@ struct tracker_audio_s *tracker_get_audio_stream(tracker_t tracker, glc_stream_i
int tracker_init(tracker_t *tracker, glc_t *glc)
{
- *tracker = (tracker_t) malloc(sizeof(struct tracker_s));
- memset(*tracker, 0, sizeof(struct tracker_s));
-
+ *tracker = (tracker_t) calloc(1, sizeof(struct tracker_s));
return 0;
}
@@ -91,8 +89,7 @@ struct tracker_video_s *tracker_get_video_stream(tracker_t tracker, glc_stream_i
}
if (video == NULL) {
- video = malloc(sizeof(struct tracker_video_s));
- memset(video, 0, sizeof(struct tracker_video_s));
+ video = (struct tracker_video_s *) calloc(1, sizeof(struct tracker_video_s));
video->next = tracker->video_streams;
tracker->video_streams = video;
@@ -112,8 +109,7 @@ struct tracker_audio_s *tracker_get_audio_stream(tracker_t tracker, glc_stream_i
}
if (audio == NULL) {
- audio = malloc(sizeof(struct tracker_audio_s));
- memset(audio, 0, sizeof(struct tracker_audio_s));
+ audio = (struct tracker_audio_s *) calloc(1, sizeof(struct tracker_audio_s));
audio->next = tracker->audio_streams;
tracker->audio_streams = audio;
View
7 src/glc/core/ycbcr.c
@@ -107,8 +107,7 @@ void ycbcr_bgr_to_jpeg420_scale(ycbcr_t ycbcr, struct ycbcr_video_stream_s *vide
int ycbcr_init(ycbcr_t *ycbcr, glc_t *glc)
{
- *ycbcr = malloc(sizeof(struct ycbcr_s));
- memset(*ycbcr, 0, sizeof(struct ycbcr_s));
+ *ycbcr = (struct ycbcr_s *) calloc(1, sizeof(struct ycbcr_s));
(*ycbcr)->glc = glc;
@@ -240,8 +239,8 @@ void ycbcr_get_video_stream(ycbcr_t ycbcr, glc_stream_id_t id, struct ycbcr_vide
}
if (*video == NULL) {
- *video = malloc(sizeof(struct ycbcr_video_stream_s));
- memset(*video, 0, sizeof(struct ycbcr_video_stream_s));
+ *video = (struct ycbcr_video_stream_s *)
+ calloc(1, sizeof(struct ycbcr_video_stream_s));
(*video)->next = ycbcr->video;
ycbcr->video = *video;
View
6 src/glc/export/img.c
@@ -72,8 +72,7 @@ int img_write_png(img_t img, const unsigned char *pic,
int img_init(img_t *img, glc_t *glc)
{
- *img = (img_t) malloc(sizeof(struct img_s));
- memset(*img, 0, sizeof(struct img_s));
+ *img = (img_t) calloc(1, sizeof(struct img_s));
(*img)->glc = glc;
(*img)->fps = 30;
@@ -210,7 +209,8 @@ int img_video_format_message(img_t img, glc_video_format_message_t *video_format
}
if (img->prev_video_frame_message)
- img->prev_video_frame_message = (unsigned char *) realloc(img->prev_video_frame_message, img->row * img->h);
+ img->prev_video_frame_message = (unsigned char *)
+ realloc(img->prev_video_frame_message, img->row * img->h);
else
img->prev_video_frame_message = (unsigned char *) malloc(img->row * img->h);
memset(img->prev_video_frame_message, 0, img->row * img->h);
View
6 src/glc/export/wav.c
@@ -82,8 +82,7 @@ int wav_write_audio(wav_t wav, glc_audio_data_header_t *audio_msg, char *data);
int wav_init(wav_t *wav, glc_t *glc)
{
- *wav = (wav_t) malloc(sizeof(struct wav_s));
- memset(*wav, 0, sizeof(struct wav_s));
+ *wav = (wav_t) calloc(1, sizeof(struct wav_s));
(*wav)->glc = glc;
@@ -93,8 +92,7 @@ int wav_init(wav_t *wav, glc_t *glc)
(*wav)->interpolate = 1;
(*wav)->silence_size = 1024;
- (*wav)->silence = (char *) malloc((*wav)->silence_size);
- memset((*wav)->silence, 0, (*wav)->silence_size);
+ (*wav)->silence = (char *) calloc(1, (*wav)->silence_size);
(*wav)->thread.flags = GLC_THREAD_READ;
(*wav)->thread.ptr = *wav;
View
9 src/glc/export/yuv4mpeg.c
@@ -58,8 +58,7 @@ int yuv4mpeg_write_video_frame_message(yuv4mpeg_t yuv4mpeg, char *pic);
int yuv4mpeg_init(yuv4mpeg_t *yuv4mpeg, glc_t *glc)
{
- *yuv4mpeg = (yuv4mpeg_t) malloc(sizeof(struct yuv4mpeg_s));
- memset(*yuv4mpeg, 0, sizeof(struct yuv4mpeg_s));
+ *yuv4mpeg = (yuv4mpeg_t) calloc(1, sizeof(struct yuv4mpeg_s));
(*yuv4mpeg)->glc = glc;
(*yuv4mpeg)->fps = 30;
@@ -198,12 +197,14 @@ int yuv4mpeg_handle_hdr(yuv4mpeg_t yuv4mpeg, glc_video_format_message_t *video_f
if (yuv4mpeg->interpolate) {
if (yuv4mpeg->prev_video_frame_message)
- yuv4mpeg->prev_video_frame_message = (char *) realloc(yuv4mpeg->prev_video_frame_message, yuv4mpeg->size);
+ yuv4mpeg->prev_video_frame_message = (char *)
+ realloc(yuv4mpeg->prev_video_frame_message, yuv4mpeg->size);
else
yuv4mpeg->prev_video_frame_message = (char *) malloc(yuv4mpeg->size);
/* Set Y' 0 */
- memset(yuv4mpeg->prev_video_frame_message, 0, video_format->width * video_format->height);
+ memset(yuv4mpeg->prev_video_frame_message, 0,
+ video_format->width * video_format->height);
/* Set CbCr 128 */
memset(&yuv4mpeg->prev_video_frame_message[video_format->width * video_format->height],
128, (video_format->width * video_format->height) / 2);
View
3  src/glc/play/alsa_play.c
@@ -75,8 +75,7 @@ snd_pcm_format_t glc_fmt_to_pcm_fmt(glc_audio_format_t format)
int alsa_play_init(alsa_play_t *alsa_play, glc_t *glc)
{
- *alsa_play = (alsa_play_t) malloc(sizeof(struct alsa_play_s));
- memset(*alsa_play, 0, sizeof(struct alsa_play_s));
+ *alsa_play = (alsa_play_t) calloc(1, sizeof(struct alsa_play_s));
(*alsa_play)->glc = glc;
(*alsa_play)->device = "default";
View
11 src/glc/play/demux.c
@@ -91,8 +91,7 @@ int demux_audio_stream_clean(demux_t demux, struct demux_audio_stream_s *audio);
int demux_init(demux_t *demux, glc_t *glc)
{
- *demux = malloc(sizeof(struct demux_s));
- memset(*demux, 0, sizeof(struct demux_s));
+ *demux = (struct demux_s *) calloc(1, sizeof(struct demux_s));
(*demux)->glc = glc;
(*demux)->alsa_playback_device = "default";
@@ -330,8 +329,8 @@ int demux_video_stream_get(demux_t demux, glc_stream_id_t id, struct demux_video
}
if (*video == NULL) {
- *video = malloc(sizeof(struct demux_video_stream_s));
- memset(*video, 0, sizeof(struct demux_video_stream_s));
+ *video = (struct demux_video_stream_s *)
+ calloc(1, sizeof(struct demux_video_stream_s));
(*video)->id = id;
if ((ret = ps_buffer_init(&(*video)->buffer, &demux->video_bufferattr)))
@@ -434,8 +433,8 @@ int demux_audio_stream_get(demux_t demux, glc_stream_id_t id,
}
if (*audio == NULL) {
- *audio = malloc(sizeof(struct demux_audio_stream_s));
- memset(*audio, 0, sizeof(struct demux_audio_stream_s));
+ *audio = (struct demux_audio_stream_s *)
+ calloc(1, sizeof(struct demux_audio_stream_s));
(*audio)->id = id;
if ((ret = ps_buffer_init(&(*audio)->buffer, &demux->audio_bufferattr)))
View
10 src/glc/play/gl_play.c
@@ -97,8 +97,7 @@ int gl_play_next_texture_size(gl_play_t gl_play, unsigned int number);
int gl_play_init(gl_play_t *gl_play, glc_t *glc)
{
- *gl_play = (gl_play_t) malloc(sizeof(struct gl_play_s));
- memset(*gl_play, 0, sizeof(struct gl_play_s));
+ *gl_play = (gl_play_t) calloc(1, sizeof(struct gl_play_s));
(*gl_play)->glc = glc;
(*gl_play)->id = 1;
@@ -431,15 +430,14 @@ int gl_play_create_textures(gl_play_t gl_play)
}
/* create textures */
- gl_play->tiles = (GLuint *) malloc(sizeof(GLuint) * gl_play->tiles_x * gl_play->tiles_y);
- memset(gl_play->tiles, 0, sizeof(GLuint) * gl_play->tiles_x * gl_play->tiles_y);
+ gl_play->tiles = (GLuint *) calloc(gl_play->tiles_x * gl_play->tiles_y, sizeof(GLuint));
glEnable(GL_TEXTURE_2D);
glGenTextures(gl_play->tiles_x * gl_play->tiles_y, gl_play->tiles);
/* data for vertices 4 x 2 coordinates per each */
- gl_play->vertices = (GLint *) malloc(sizeof(GLint) * gl_play->tiles_x * gl_play->tiles_y * 8);
- memset(gl_play->vertices, 0, sizeof(GLint) * gl_play->tiles_x * gl_play->tiles_y * 8);
+ gl_play->vertices = (GLint *)
+ calloc(gl_play->tiles_x * gl_play->tiles_y, sizeof(GLint) * 8);
/* and init data for drawing */
height_r = gl_play->h;
View
6 src/hook/alsa.c
@@ -122,8 +122,8 @@ int alsa_parse_capture_cfg(const char *cfg)
sscanf(args, ",%u,%u", &rate, &channels);
next = strstr(device, ";");
- stream = malloc(sizeof(struct alsa_capture_stream_s));
- memset(stream, 0, sizeof(struct alsa_capture_stream_s));
+ stream = (struct alsa_capture_stream_s *)
+ calloc(1, sizeof(struct alsa_capture_stream_s));
if (args)
len = args - device;
@@ -132,7 +132,7 @@ int alsa_parse_capture_cfg(const char *cfg)
else
len = strlen(device);
- stream->device = (char *) malloc(sizeof(char) * len);
+ stream->device = (char *) malloc(sizeof(char) * (len+1));
memcpy(stream->device, device, len);
stream->device[len] = '\0';
Something went wrong with that request. Please try again.