diff --git a/src/alg_sec.cpp b/src/alg_sec.cpp index cb3d6a33..4ee538a0 100644 --- a/src/alg_sec.cpp +++ b/src/alg_sec.cpp @@ -385,7 +385,10 @@ static void algsec_params_deinit(ctx_algsec_model &algmdl) { if (algmdl.algsec_params != NULL){ util_parms_free(algmdl.algsec_params); - util_free_var(algmdl.algsec_params); + if (algmdl.algsec_params != NULL) { + free(algmdl.algsec_params); + } + algmdl.algsec_params = NULL; } } @@ -558,7 +561,10 @@ void algsec_deinit(ctx_cam *cam) } } if (cam->algsec->image_norm != NULL){ - util_free_var(cam->algsec->image_norm); + if (cam->algsec->image_norm != NULL) { + free(cam->algsec->image_norm); + } + cam->algsec->image_norm = NULL; } if (waitcnt == 1000){ diff --git a/src/conf.cpp b/src/conf.cpp index e8d5de47..fcd43561 100644 --- a/src/conf.cpp +++ b/src/conf.cpp @@ -4327,7 +4327,10 @@ void conf_deinit(struct ctx_motapp *motapp) indx++; } - util_free_var(motapp->cam_list); + if (motapp->cam_list != NULL) { + free(motapp->cam_list); + } + motapp->cam_list = NULL; } diff --git a/src/dbse.cpp b/src/dbse.cpp index 14e4a48e..d620ab39 100644 --- a/src/dbse.cpp +++ b/src/dbse.cpp @@ -82,7 +82,10 @@ void dbse_global_deinit(struct ctx_motapp *motapp) indx = 0; while (motapp->cam_list[indx] != NULL) { - util_free_var(motapp->cam_list[indx]->dbse); + if (motapp->cam_list[indx]->dbse != NULL) { + free(motapp->cam_list[indx]->dbse); + } + motapp->cam_list[indx]->dbse = NULL; indx++; } diff --git a/src/event.cpp b/src/event.cpp index 3cf66570..c1694c35 100644 --- a/src/event.cpp +++ b/src/event.cpp @@ -652,7 +652,10 @@ static void event_movie_newfile(struct ctx_cam *cam, motion_event evnt if (retcd < 0) { MOTION_LOG(ERR, TYPE_EVENTS, NO_ERRNO ,_("Error opening ctx_cam for movie output.")); - util_free_var(cam->movie_norm); + if (cam->movie_norm != NULL) { + free(cam->movie_norm); + } + cam->movie_norm = NULL; return; } event(cam, EVENT_FILECREATE, NULL, cam->movie_norm->filename, (void *)FTYPE_MPEG, ts1); @@ -663,7 +666,10 @@ static void event_movie_newfile(struct ctx_cam *cam, motion_event evnt if (retcd < 0) { MOTION_LOG(ERR, TYPE_EVENTS, NO_ERRNO ,_("Error creating motion file [%s]"), cam->movie_motion->filename); - util_free_var(cam->movie_motion); + if (cam->movie_motion != NULL) { + free(cam->movie_motion); + } + cam->movie_motion = NULL; return; } } @@ -684,7 +690,10 @@ static void event_movie_timelapse(struct ctx_cam *cam, motion_event evnt if (retcd < 0) { MOTION_LOG(ERR, TYPE_EVENTS, NO_ERRNO ,_("Error creating timelapse file [%s]"), cam->movie_timelapse->filename); - util_free_var(cam->movie_timelapse); + if (cam->movie_timelapse != NULL) { + free(cam->movie_timelapse); + } + cam->movie_timelapse = NULL; return; } event(cam, EVENT_FILECREATE, NULL, cam->movie_timelapse->filename @@ -728,13 +737,19 @@ static void event_movie_closefile(struct ctx_cam *cam, motion_event evnt if (cam->movie_norm) { movie_close(cam->movie_norm); - util_free_var(cam->movie_norm); + if (cam->movie_norm != NULL) { + free(cam->movie_norm); + } + cam->movie_norm = NULL; event(cam, EVENT_FILECLOSE, NULL, cam->newfilename, (void *)FTYPE_MPEG, ts1); } if (cam->movie_motion) { movie_close(cam->movie_motion); - util_free_var(cam->movie_motion); + if (cam->movie_motion != NULL) { + free(cam->movie_motion); + } + cam->movie_motion = NULL; event(cam, EVENT_FILECLOSE, NULL, cam->motionfilename, (void *)FTYPE_MPEG_MOTION, ts1); } @@ -751,7 +766,10 @@ static void event_movie_timelapseend(struct ctx_cam *cam, motion_event evnt if (cam->movie_timelapse) { movie_close(cam->movie_timelapse); - util_free_var(cam->movie_timelapse); + if (cam->movie_timelapse != NULL) { + free(cam->movie_timelapse); + } + cam->movie_timelapse = NULL; event(cam, EVENT_FILECLOSE, NULL, cam->timelapsefilename, (void *)FTYPE_MPEG_TIMELAPSE, ts1); } } diff --git a/src/exif.cpp b/src/exif.cpp index d14126fb..ddd0f259 100644 --- a/src/exif.cpp +++ b/src/exif.cpp @@ -345,7 +345,10 @@ unsigned exif_prepare(unsigned char **exif, const struct ctx_cam *cam, /* assert we didn't underestimate the original buffer size */ assert(marker_len <= buffer_size); - util_free_var(description); + if (description != NULL) { + free(description); + } + description = NULL; *exif = marker; return marker_len; diff --git a/src/motion_loop.cpp b/src/motion_loop.cpp index 58c68010..06beff20 100644 --- a/src/motion_loop.cpp +++ b/src/motion_loop.cpp @@ -74,7 +74,10 @@ static void mlp_ring_resize(struct ctx_cam *cam, int new_size) } } - util_free_var(cam->imgs.image_ring); + if (cam->imgs.image_ring != NULL) { + free(cam->imgs.image_ring); + } + cam->imgs.image_ring = NULL; cam->imgs.image_ring = tmp; cam->current_image = NULL; @@ -96,10 +99,20 @@ static void mlp_ring_destroy(struct ctx_cam *cam) } for (i = 0; i < cam->imgs.ring_size; i++) { - util_free_var(cam->imgs.image_ring[i].image_norm); - util_free_var(cam->imgs.image_ring[i].image_high); + if (cam->imgs.image_ring[i].image_norm != NULL) { + free(cam->imgs.image_ring[i].image_norm); + } + cam->imgs.image_ring[i].image_norm = NULL; + + if (cam->imgs.image_ring[i].image_high != NULL) { + free(cam->imgs.image_ring[i].image_high); + } + cam->imgs.image_ring[i].image_high = NULL; } - util_free_var(cam->imgs.image_ring); + if (cam->imgs.image_ring != NULL) { + free(cam->imgs.image_ring); + } + cam->imgs.image_ring = NULL; cam->imgs.image_ring = NULL; cam->current_image = NULL; @@ -733,7 +746,16 @@ void mlp_cleanup(struct ctx_cam *cam) { event(cam, EVENT_TIMELAPSEEND, NULL, NULL, NULL, NULL); - event(cam, EVENT_ENDMOTION, NULL, NULL, NULL, NULL); + + /*if (cam->event_nr == cam->prev_event) { + mlp_ring_process(cam); + if (cam->imgs.image_preview.diffs) { + event(cam, EVENT_IMAGE_PREVIEW, NULL, NULL, NULL, &cam->current_image->imgts); + cam->imgs.image_preview.diffs = 0; + } + */ + event(cam, EVENT_ENDMOTION, NULL, NULL, NULL, &cam->current_image->imgts); + /* } */ webu_stream_deinit(cam); @@ -743,25 +765,100 @@ void mlp_cleanup(struct ctx_cam *cam) mlp_cam_close(cam); } - util_free_var(cam->imgs.image_motion.image_norm); - util_free_var(cam->imgs.ref); - util_free_var(cam->imgs.ref_dyn); - util_free_var(cam->imgs.image_virgin); - util_free_var(cam->imgs.image_vprvcy); - util_free_var(cam->imgs.labels); - util_free_var(cam->imgs.labelsize); - util_free_var(cam->imgs.smartmask); - util_free_var(cam->imgs.smartmask_final); - util_free_var(cam->imgs.smartmask_buffer); - util_free_var(cam->imgs.mask); - util_free_var(cam->imgs.mask_privacy); - util_free_var(cam->imgs.mask_privacy_uv); - util_free_var(cam->imgs.mask_privacy_high); - util_free_var(cam->imgs.mask_privacy_high_uv); - util_free_var(cam->imgs.common_buffer); - util_free_var(cam->imgs.image_secondary); - util_free_var(cam->imgs.image_preview.image_norm); - util_free_var(cam->imgs.image_preview.image_high); + if (cam->imgs.image_motion.image_norm != NULL) { + free(cam->imgs.image_motion.image_norm); + } + cam->imgs.image_motion.image_norm = NULL; + + if (cam->imgs.ref != NULL) { + free(cam->imgs.ref); + } + cam->imgs.ref = NULL; + + if (cam->imgs.ref_dyn != NULL) { + free(cam->imgs.ref_dyn); + } + cam->imgs.ref_dyn = NULL; + + if (cam->imgs.image_virgin != NULL) { + free(cam->imgs.image_virgin); + } + cam->imgs.image_virgin = NULL; + + if (cam->imgs.image_vprvcy != NULL) { + free(cam->imgs.image_vprvcy); + } + cam->imgs.image_vprvcy = NULL; + + if (cam->imgs.labels != NULL) { + free(cam->imgs.labels); + } + cam->imgs.labels = NULL; + + if (cam->imgs.labelsize != NULL) { + free(cam->imgs.labelsize); + } + cam->imgs.labelsize = NULL; + + if (cam->imgs.smartmask != NULL) { + free(cam->imgs.smartmask); + } + cam->imgs.smartmask = NULL; + + if (cam->imgs.smartmask_final != NULL) { + free(cam->imgs.smartmask_final); + } + cam->imgs.smartmask_final = NULL; + + if (cam->imgs.smartmask_buffer != NULL) { + free(cam->imgs.smartmask_buffer); + } + cam->imgs.smartmask_buffer = NULL; + + if (cam->imgs.mask != NULL) { + free(cam->imgs.mask); + } + cam->imgs.mask = NULL; + + if (cam->imgs.mask_privacy != NULL) { + free(cam->imgs.mask_privacy); + } + cam->imgs.mask_privacy = NULL; + + if (cam->imgs.mask_privacy_uv != NULL) { + free(cam->imgs.mask_privacy_uv); + } + cam->imgs.mask_privacy_uv = NULL; + + if (cam->imgs.mask_privacy_high != NULL) { + free(cam->imgs.mask_privacy_high); + } + cam->imgs.mask_privacy_high = NULL; + + if (cam->imgs.mask_privacy_high_uv != NULL) { + free(cam->imgs.mask_privacy_high_uv); + } + cam->imgs.mask_privacy_high_uv = NULL; + + if (cam->imgs.common_buffer != NULL) { + free(cam->imgs.common_buffer); + } + cam->imgs.common_buffer = NULL; + + if (cam->imgs.image_secondary != NULL) { + free(cam->imgs.image_secondary); + } + cam->imgs.image_secondary = NULL; + + if (cam->imgs.image_preview.image_norm != NULL) { + free(cam->imgs.image_preview.image_norm); + } + cam->imgs.image_preview.image_norm = NULL; + + if (cam->imgs.image_preview.image_high != NULL) { + free(cam->imgs.image_preview.image_high); + } + cam->imgs.image_preview.image_high = NULL; mlp_ring_destroy(cam); /* Cleanup the precapture ring buffer */ @@ -1244,6 +1341,9 @@ static void mlp_actions_event(struct ctx_cam *cam) if (cam->event_stop) { if (cam->event_nr == cam->prev_event) { + + mlp_ring_process(cam); + if (cam->imgs.image_preview.diffs) { event(cam, EVENT_IMAGE_PREVIEW, NULL, NULL, NULL, &cam->current_image->imgts); cam->imgs.image_preview.diffs = 0; diff --git a/src/motionplus.cpp b/src/motionplus.cpp index 574e0279..e5cd2234 100644 --- a/src/motionplus.cpp +++ b/src/motionplus.cpp @@ -683,7 +683,10 @@ static void motion_cam_delete(struct ctx_motapp *motapp) return; } - util_free_var(motapp->cam_list[motapp->cam_delete]->dbse); + if (motapp->cam_list[motapp->cam_delete]->dbse != NULL) { + free(motapp->cam_list[motapp->cam_delete]->dbse); + } + motapp->cam_list[motapp->cam_delete]->dbse = NULL; /* Delete the config context */ delete motapp->cam_list[motapp->cam_delete]->conf; @@ -706,7 +709,9 @@ static void motion_cam_delete(struct ctx_motapp *motapp) /* Swap out the old list with the new */ pthread_mutex_lock(&motapp->mutex_camlst); - util_free_var(motapp->cam_list); + if (motapp->cam_list != NULL) { + free(motapp->cam_list); + } motapp->cam_list = tmp; pthread_mutex_unlock(&motapp->mutex_camlst); diff --git a/src/movie.cpp b/src/movie.cpp index 822c9fe9..5f62d611 100644 --- a/src/movie.cpp +++ b/src/movie.cpp @@ -45,7 +45,8 @@ static void movie_free_nal(struct ctx_movie *movie) { if (movie->nal_info) { - util_free_var(movie->nal_info); + free(movie->nal_info); + movie->nal_info = NULL; movie->nal_info_len = 0; } } @@ -145,7 +146,10 @@ static int movie_get_oformat(struct ctx_movie *movie) MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO ,_("Error setting base file name")); movie_free_context(movie); - util_free_var(codec_name); + if (codec_name != NULL) { + free(codec_name); + } + codec_name = NULL; return -1; } @@ -160,10 +164,16 @@ static int movie_get_oformat(struct ctx_movie *movie) MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO ,_("Error setting timelapse append for codec %s"), codec_name); movie_free_context(movie); - util_free_var(codec_name); + if (codec_name != NULL) { + free(codec_name); + } + codec_name = NULL; return -1; } - util_free_var(codec_name); + if (codec_name != NULL) { + free(codec_name); + } + codec_name = NULL; return 0; } @@ -220,7 +230,10 @@ static int movie_get_oformat(struct ctx_movie *movie) MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO ,_("Error setting file name")); movie_free_context(movie); - util_free_var(codec_name); + if (codec_name != NULL) { + free(codec_name); + } + codec_name = NULL; return -1; } @@ -228,18 +241,28 @@ static int movie_get_oformat(struct ctx_movie *movie) MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO ,_("codec option value %s is not supported"), codec_name); movie_free_context(movie); - util_free_var(codec_name); + if (codec_name != NULL) { + free(codec_name); + } + codec_name = NULL; return -1; } if (movie->oc->oformat->video_codec == MY_CODEC_ID_NONE) { MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, _("Could not get the codec")); movie_free_context(movie); - util_free_var(codec_name); + if (codec_name != NULL) { + free(codec_name); + } + codec_name = NULL; return -1; } - util_free_var(codec_name); + if (codec_name != NULL) { + free(codec_name); + } + codec_name = NULL; + return 0; } @@ -336,7 +359,10 @@ static int movie_encode_video(struct ctx_movie *movie) movie->pkt.pts = movie->picture->pts; movie->pkt.dts = movie->pkt.pts; - util_free_var(video_outbuf); + if (video_outbuf != NULL) { + free(video_outbuf); + } + video_outbuf = NULL; /* This kills compiler warnings. Nal setting is only for recent movie versions*/ if (movie->preferred_codec == USER_CODEC_V4L2M2M) { @@ -1455,13 +1481,15 @@ void movie_close(struct ctx_movie *movie) if (movie_flush_codec(movie) < 0) { MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, _("Error flushing codec")); } - if (movie->oc->pb != NULL) { - if (movie->tlapse != TIMELAPSE_APPEND) { - av_write_trailer(movie->oc); - } - if (!(movie->oc->oformat->flags & AVFMT_NOFILE)) { + if (movie->oc != NULL) { + if (movie->oc->pb != NULL) { if (movie->tlapse != TIMELAPSE_APPEND) { - avio_close(movie->oc->pb); + av_write_trailer(movie->oc); + } + if (!(movie->oc->oformat->flags & AVFMT_NOFILE)) { + if (movie->tlapse != TIMELAPSE_APPEND) { + avio_close(movie->oc->pb); + } } } } @@ -1478,7 +1506,6 @@ int movie_put_image(struct ctx_movie *movie, struct ctx_image_data *img_data, co int retcd = 0; int cnt = 0; - if (movie->passthrough) { retcd = movie_passthru_put(movie, img_data); return retcd; diff --git a/src/util.cpp b/src/util.cpp index eb1f776c..f56ce2d7 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -1222,12 +1222,3 @@ void util_exec_command(struct ctx_cam *cam, const char *command, char *filename, ,_("Executing external command '%s'"), stamp); } -/* Free a pointer and set to null */ -void util_free_var(void *parm) -{ - if (parm != NULL) { - free(parm); - } - parm = NULL; -} - diff --git a/src/util.hpp b/src/util.hpp index 2c24f42d..f4da421c 100644 --- a/src/util.hpp +++ b/src/util.hpp @@ -132,8 +132,9 @@ void util_parms_parse(struct ctx_params *params, std::string confline); void util_parms_add_default(ctx_params *params, std::string parm_nm, std::string parm_vl); + void util_parms_free(struct ctx_params *params); void util_parms_update(struct ctx_params *params, std::string &confline); - void util_free_var(void *parm); + #endif diff --git a/src/video_v4l2.cpp b/src/video_v4l2.cpp index 1c2c8b42..cd923efb 100644 --- a/src/video_v4l2.cpp +++ b/src/video_v4l2.cpp @@ -554,7 +554,10 @@ static int v4l2_set_palette(ctx_v4l2cam *v4l2cam) if ((indx_palette >= 0) && (indx_palette <= V4L2_PALETTE_COUNT_MAX)) { retcd = v4l2_set_pixfmt(v4l2cam, palette_array[indx_palette].v4l2id); if (retcd >= 0) { - util_free_var(palette_array); + if (palette_array != NULL) { + free(palette_array); + } + palette_array = NULL; return 0; } MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO @@ -598,7 +601,10 @@ static int v4l2_set_palette(ctx_v4l2cam *v4l2cam) MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO ,_("Selected palette %s") ,palette_array[indx_palette].fourcc); - util_free_var(palette_array); + if (palette_array != NULL) { + free(palette_array); + } + palette_array = NULL; return 0; } MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO @@ -608,8 +614,10 @@ static int v4l2_set_palette(ctx_v4l2cam *v4l2cam) MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO ,_("Unable to find a compatible palette format.")); - - util_free_var(palette_array); + if (palette_array != NULL) { + free(palette_array); + } + palette_array = NULL; return -1; @@ -668,7 +676,10 @@ static int v4l2_set_mmap(ctx_v4l2cam *v4l2cam) MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO ,_("Error querying buffer %i\nVIDIOC_QUERYBUF: ") ,buffer_index); - util_free_var(v4l2cam->buffers); + if (v4l2cam->buffers != NULL) { + free(v4l2cam->buffers); + } + v4l2cam->buffers = NULL; return -1; } @@ -679,7 +690,10 @@ static int v4l2_set_mmap(ctx_v4l2cam *v4l2cam) if (v4l2cam->buffers[buffer_index].ptr == MAP_FAILED) { MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO ,_("Error mapping buffer %i mmap"), buffer_index); - util_free_var(v4l2cam->buffers); + if (v4l2cam->buffers != NULL) { + free(v4l2cam->buffers); + } + v4l2cam->buffers = NULL; return -1; } @@ -1083,7 +1097,10 @@ static void v4l2_log_formats(ctx_v4l2cam *v4l2cam) dev_format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; } - util_free_var(palette_array); + if (palette_array != NULL) { + free(palette_array); + } + palette_array = NULL; return; } @@ -1145,23 +1162,37 @@ void v4l2_cleanup(ctx_cam *cam) for (indx = 0; indx < (int)cam->v4l2cam->req.count; indx++){ munmap(cam->v4l2cam->buffers[indx].ptr, cam->v4l2cam->buffers[indx].size); } - util_free_var(cam->v4l2cam->buffers); + if (cam->v4l2cam->buffers != NULL) { + free(cam->v4l2cam->buffers); + } + cam->v4l2cam->buffers = NULL; } if (cam->v4l2cam->devctrl_count != 0) { for (indx = 0; indx < cam->v4l2cam->devctrl_count; indx++){ - util_free_var(cam->v4l2cam->devctrl_array[indx].ctrl_iddesc); - util_free_var(cam->v4l2cam->devctrl_array[indx].ctrl_name); + if (cam->v4l2cam->devctrl_array[indx].ctrl_iddesc != NULL) { + free(cam->v4l2cam->devctrl_array[indx].ctrl_iddesc); + } + cam->v4l2cam->devctrl_array[indx].ctrl_iddesc = NULL; + + if (cam->v4l2cam->devctrl_array[indx].ctrl_name != NULL) { + free(cam->v4l2cam->devctrl_array[indx].ctrl_name); + } + cam->v4l2cam->devctrl_array[indx].ctrl_name = NULL; } - util_free_var(cam->v4l2cam->devctrl_array); + if (cam->v4l2cam->devctrl_array != NULL) { + free(cam->v4l2cam->devctrl_array); + } + cam->v4l2cam->devctrl_array = NULL; } cam->v4l2cam->devctrl_count=0; util_parms_free(cam->v4l2cam->params); + if (cam->v4l2cam != NULL) { + free(cam->v4l2cam); + } + cam->v4l2cam = NULL; - util_free_var(cam->v4l2cam->params); - - util_free_var(cam->v4l2cam); cam->running_cam = FALSE; #else (void)cam; diff --git a/src/webu.cpp b/src/webu.cpp index 059813d4..41a3d230 100644 --- a/src/webu.cpp +++ b/src/webu.cpp @@ -101,17 +101,45 @@ static void webu_context_free(struct webui_ctx *webui) { int indx; - util_free_var(webui->auth_user); - util_free_var(webui->auth_pass); - util_free_var(webui->auth_opaque); - util_free_var(webui->auth_realm); - util_free_var(webui->resp_image); + if (webui->auth_user != NULL) { + free(webui->auth_user); + } + webui->auth_user = NULL; + + if (webui->auth_pass != NULL) { + free(webui->auth_pass); + } + webui->auth_pass = NULL; + + if (webui->auth_opaque != NULL) { + free(webui->auth_opaque); + } + webui->auth_opaque = NULL; + + if (webui->auth_realm != NULL) { + free(webui->auth_realm); + } + webui->auth_realm = NULL; + + if (webui->resp_image != NULL) { + free(webui->resp_image); + } + webui->resp_image = NULL; for (indx = 0; indxpost_sz; indx++) { - util_free_var(webui->post_info[indx].key_nm); - util_free_var(webui->post_info[indx].key_val); + if (webui->post_info[indx].key_nm != NULL) { + free(webui->post_info[indx].key_nm); + } + webui->post_info[indx].key_nm = NULL; + if (webui->post_info[indx].key_val != NULL) { + free(webui->post_info[indx].key_val); + } + webui->post_info[indx].key_val = NULL; } - util_free_var(webui->post_info); + if (webui->post_info != NULL) { + free(webui->post_info); + } + webui->post_info = NULL; delete webui; @@ -355,10 +383,16 @@ static mhdrslt webu_mhd_digest(struct webui_ctx *webui) if (mystrne(user, webui->auth_user)) { MOTION_LOG(ALR, TYPE_STREAM, NO_ERRNO ,_("Failed authentication from %s"), webui->clientip.c_str()); - util_free_var(user); + if (user != NULL) { + free(user); + } + user = NULL; return webu_mhd_digest_fail(webui, MHD_NO); } - util_free_var(user); + if (user != NULL) { + free(user); + } + user = NULL; /* Check the password as well*/ retcd = MHD_digest_auth_check(webui->connection, webui->auth_realm @@ -418,21 +452,39 @@ static mhdrslt webu_mhd_basic(struct webui_ctx *webui) user = MHD_basic_auth_get_username_password (webui->connection, &pass); if ((user == NULL) || (pass == NULL)) { - util_free_var(user); - util_free_var(pass); + if (user != NULL) { + free(user); + } + user = NULL; + if (pass != NULL) { + free(pass); + } + pass = NULL; return webu_mhd_basic_fail(webui); } if ((mystrne(user, webui->auth_user)) || (mystrne(pass, webui->auth_pass))) { MOTION_LOG(ALR, TYPE_STREAM, NO_ERRNO ,_("Failed authentication from %s"),webui->clientip.c_str()); - util_free_var(user); - util_free_var(pass); + if (user != NULL) { + free(user); + } + user = NULL; + if (pass != NULL) { + free(pass); + } + pass = NULL; return webu_mhd_basic_fail(webui); } - util_free_var(user); - util_free_var(pass); + if (user != NULL) { + free(user); + } + user = NULL; + if (pass != NULL) { + free(pass); + } + pass = NULL; webui->authenticated = true; @@ -446,8 +498,14 @@ static void webu_mhd_auth_parse(struct webui_ctx *webui) int auth_len; char *col_pos; - util_free_var(webui->auth_user); - util_free_var(webui->auth_pass); + if (webui->auth_user != NULL) { + free(webui->auth_user); + } + webui->auth_user = NULL; + if (webui->auth_pass != NULL) { + free(webui->auth_pass); + } + webui->auth_pass = NULL; auth_len = webui->motapp->cam_list[0]->conf->webcontrol_authentication.length(); col_pos =(char*) strstr(webui->motapp->cam_list[0]->conf->webcontrol_authentication.c_str() ,":"); diff --git a/src/webu_stream.cpp b/src/webu_stream.cpp index 793ce955..eafb6b5f 100644 --- a/src/webu_stream.cpp +++ b/src/webu_stream.cpp @@ -32,7 +32,10 @@ static void webu_stream_mjpeg_checkbuffers(struct webui_ctx *webui) { if (webui->resp_size < (size_t)webui->cam->imgs.size_norm) { if (webui->resp_image != NULL) { - util_free_var(webui->resp_image); + if (webui->resp_image != NULL) { + free(webui->resp_image); + } + webui->resp_image = NULL; } webui->resp_image =(char*) mymalloc(webui->cam->imgs.size_norm); memset(webui->resp_image,'\0',webui->cam->imgs.size_norm); @@ -481,12 +484,35 @@ void webu_stream_deinit(struct ctx_cam *cam) pthread_mutex_destroy(&cam->stream.mutex); - util_free_var(cam->imgs.image_substream); - util_free_var(cam->stream.norm.jpeg_data); - util_free_var(cam->stream.sub.jpeg_data); - util_free_var(cam->stream.motion.jpeg_data); - util_free_var(cam->stream.source.jpeg_data); - util_free_var(cam->stream.secondary.jpeg_data); + if (cam->imgs.image_substream != NULL) { + free(cam->imgs.image_substream); + } + cam->imgs.image_substream = NULL; + + if (cam->stream.norm.jpeg_data != NULL) { + free(cam->stream.norm.jpeg_data); + } + cam->stream.norm.jpeg_data = NULL; + + if (cam->stream.sub.jpeg_data != NULL) { + free(cam->stream.sub.jpeg_data); + } + cam->stream.sub.jpeg_data = NULL; + + if (cam->stream.motion.jpeg_data != NULL) { + free(cam->stream.motion.jpeg_data); + } + cam->stream.motion.jpeg_data = NULL; + + if (cam->stream.source.jpeg_data != NULL) { + free(cam->stream.source.jpeg_data); + } + cam->stream.source.jpeg_data = NULL; + + if (cam->stream.secondary.jpeg_data != NULL) { + free(cam->stream.secondary.jpeg_data); + } + cam->stream.secondary.jpeg_data = NULL; } @@ -611,7 +637,10 @@ static void webu_stream_getimg_secondary(struct ctx_cam *cam) cam->stream.secondary.jpeg_size = cam->imgs.size_secondary; pthread_mutex_unlock(&cam->algsec->mutex); } else { - util_free_var(cam->stream.secondary.jpeg_data); + if (cam->stream.secondary.jpeg_data != NULL) { + free(cam->stream.secondary.jpeg_data); + } + cam->stream.secondary.jpeg_data = NULL; } }