From a9a866fecbe62fd782cdac1f46eb6cbfe0d92ce3 Mon Sep 17 00:00:00 2001 From: Mr-Dave Date: Wed, 24 Jul 2024 19:54:08 -0600 Subject: [PATCH] Revise myfree method --- src/alg_sec.cpp | 2 +- src/conf.cpp | 4 ++-- src/dbse.cpp | 18 +++++++++--------- src/jpegutils.cpp | 6 +++--- src/motion_loop.cpp | 44 ++++++++++++++++++++++---------------------- src/motionplus.cpp | 2 +- src/netcam.cpp | 4 ++-- src/rotate.cpp | 4 ++-- src/util.cpp | 10 ---------- src/util.hpp | 2 +- src/video_v4l2.cpp | 6 +++--- src/webu_ans.cpp | 32 ++++++++++++++++---------------- src/webu_common.cpp | 12 ++++++------ src/webu_getimg.cpp | 24 ++++++++++++------------ src/webu_mpegts.cpp | 4 ++-- src/webu_post.cpp | 6 +++--- src/webu_stream.cpp | 4 ++-- 17 files changed, 87 insertions(+), 97 deletions(-) diff --git a/src/alg_sec.cpp b/src/alg_sec.cpp index 1ef3c1f2..ec61e31c 100644 --- a/src/alg_sec.cpp +++ b/src/alg_sec.cpp @@ -680,7 +680,7 @@ void algsec_deinit(ctx_dev *cam) } } - myfree(&cam->algsec->image_norm); + myfree(cam->algsec->image_norm); pthread_mutex_destroy(&cam->algsec->mutex); diff --git a/src/conf.cpp b/src/conf.cpp index a82cb998..4a53bbce 100644 --- a/src/conf.cpp +++ b/src/conf.cpp @@ -4326,14 +4326,14 @@ void conf_deinit(ctx_motapp *motapp) delete motapp->cam_list[indx]->conf; delete motapp->cam_list[indx]; } - myfree(&motapp->cam_list); + myfree(motapp->cam_list); motapp->cam_cnt = 0; for (indx=0; indxsnd_cnt; indx++) { delete motapp->snd_list[indx]->conf; delete motapp->snd_list[indx]; } - myfree(&motapp->snd_list); + myfree(motapp->snd_list); motapp->snd_cnt = 0; } diff --git a/src/dbse.cpp b/src/dbse.cpp index 74009e48..db0180b4 100644 --- a/src/dbse.cpp +++ b/src/dbse.cpp @@ -70,10 +70,10 @@ static void dbse_cols_free(ctx_motapp *motapp) if (motapp->dbse->cols_list != NULL) { for (indx=0; indxdbse->cols_cnt; indx++) { - myfree(&motapp->dbse->cols_list[indx].col_nm); - myfree(&motapp->dbse->cols_list[indx].col_typ); + myfree(motapp->dbse->cols_list[indx].col_nm); + myfree(motapp->dbse->cols_list[indx].col_typ); } - myfree(&motapp->dbse->cols_list); + myfree(motapp->dbse->cols_list); } motapp->dbse->cols_cnt = 0; @@ -86,14 +86,14 @@ static void dbse_movies_free(ctx_motapp *motapp) if (motapp->dbse->movie_list != NULL) { for (indx=0; indxdbse->movie_cnt; indx++) { - myfree(&motapp->dbse->movie_list[indx].movie_nm); - myfree(&motapp->dbse->movie_list[indx].movie_dir); - myfree(&motapp->dbse->movie_list[indx].full_nm); - myfree(&motapp->dbse->movie_list[indx].movie_tmc); - myfree(&motapp->dbse->movie_list[indx].movie_tml); + myfree(motapp->dbse->movie_list[indx].movie_nm); + myfree(motapp->dbse->movie_list[indx].movie_dir); + myfree(motapp->dbse->movie_list[indx].full_nm); + myfree(motapp->dbse->movie_list[indx].movie_tmc); + myfree(motapp->dbse->movie_list[indx].movie_tml); } - myfree(&motapp->dbse->movie_list); + myfree(motapp->dbse->movie_list); } motapp->dbse->movie_cnt = 0; diff --git a/src/jpegutils.cpp b/src/jpegutils.cpp index 7b802906..a7e030fe 100644 --- a/src/jpegutils.cpp +++ b/src/jpegutils.cpp @@ -367,10 +367,10 @@ uint jpgutl_exif(u_char **exif, ctx_dev *cam, timespec *ts_in1, ctx_coord *box) marker_len = exif_info->writing.data_offset + 6; - myfree(&exif_info->description); - myfree(&exif_info->datetime); + myfree(exif_info->description); + myfree(exif_info->datetime); - myfree(&exif_info); + myfree(exif_info); *exif = marker; diff --git a/src/motion_loop.cpp b/src/motion_loop.cpp index ffbdbd83..f1f41207 100644 --- a/src/motion_loop.cpp +++ b/src/motion_loop.cpp @@ -79,10 +79,10 @@ static void mlp_ring_destroy(ctx_dev *cam) } for (i = 0; i < cam->imgs.ring_size; i++) { - myfree(&cam->imgs.image_ring[i].image_norm); - myfree(&cam->imgs.image_ring[i].image_high); + myfree(cam->imgs.image_ring[i].image_norm); + myfree(cam->imgs.image_ring[i].image_high); } - myfree(&cam->imgs.image_ring); + myfree(cam->imgs.image_ring); /* * current_image is an alias from the pointers above which have @@ -679,25 +679,25 @@ void mlp_cleanup(ctx_dev *cam) mlp_cam_close(cam); } - myfree(&cam->imgs.image_motion.image_norm); - myfree(&cam->imgs.ref); - myfree(&cam->imgs.ref_dyn); - myfree(&cam->imgs.image_virgin); - myfree(&cam->imgs.image_vprvcy); - myfree(&cam->imgs.labels); - myfree(&cam->imgs.labelsize); - myfree(&cam->imgs.smartmask); - myfree(&cam->imgs.smartmask_final); - myfree(&cam->imgs.smartmask_buffer); - myfree(&cam->imgs.mask); - myfree(&cam->imgs.mask_privacy); - myfree(&cam->imgs.mask_privacy_uv); - myfree(&cam->imgs.mask_privacy_high); - myfree(&cam->imgs.mask_privacy_high_uv); - myfree(&cam->imgs.common_buffer); - myfree(&cam->imgs.image_secondary); - myfree(&cam->imgs.image_preview.image_norm); - myfree(&cam->imgs.image_preview.image_high); + myfree(cam->imgs.image_motion.image_norm); + myfree(cam->imgs.ref); + myfree(cam->imgs.ref_dyn); + myfree(cam->imgs.image_virgin); + myfree(cam->imgs.image_vprvcy); + myfree(cam->imgs.labels); + myfree(cam->imgs.labelsize); + myfree(cam->imgs.smartmask); + myfree(cam->imgs.smartmask_final); + myfree(cam->imgs.smartmask_buffer); + myfree(cam->imgs.mask); + myfree(cam->imgs.mask_privacy); + myfree(cam->imgs.mask_privacy_uv); + myfree(cam->imgs.mask_privacy_high); + myfree(cam->imgs.mask_privacy_high_uv); + myfree(cam->imgs.common_buffer); + myfree(cam->imgs.image_secondary); + myfree(cam->imgs.image_preview.image_norm); + myfree(cam->imgs.image_preview.image_high); mlp_ring_destroy(cam); /* Cleanup the precapture ring buffer */ diff --git a/src/motionplus.cpp b/src/motionplus.cpp index 726cec53..ca7b069d 100644 --- a/src/motionplus.cpp +++ b/src/motionplus.cpp @@ -969,7 +969,7 @@ static void motpls_cam_delete(ctx_motapp *motapp) pthread_mutex_lock(&motapp->mutex_camlst); delete motapp->cam_list[motapp->cam_delete]->conf; delete motapp->cam_list[motapp->cam_delete]; - myfree(&motapp->cam_list); + myfree(motapp->cam_list); motapp->cam_cnt--; motapp->cam_list = tmp; pthread_mutex_unlock(&motapp->mutex_camlst); diff --git a/src/netcam.cpp b/src/netcam.cpp index 13491f61..3b141ac5 100644 --- a/src/netcam.cpp +++ b/src/netcam.cpp @@ -359,7 +359,7 @@ void cls_netcam::pktarray_free() pktarray[indx].packet = NULL; } } - myfree(&pktarray); + myfree(pktarray); pktarray_size = 0; pktarray_index = -1; pthread_mutex_unlock(&mutex_pktarray); @@ -449,7 +449,7 @@ void cls_netcam::pktarray_resize() tmp[indx].iswritten = false; } - myfree(&pktarray); + myfree(pktarray); pktarray = tmp; pktarray_size = newsize; diff --git a/src/rotate.cpp b/src/rotate.cpp index 5774ff47..94bd615b 100644 --- a/src/rotate.cpp +++ b/src/rotate.cpp @@ -278,7 +278,7 @@ cls_rotate::cls_rotate(ctx_dev *p_cam) cls_rotate::~cls_rotate() { - myfree(&buffer_norm); - myfree(&buffer_high); + myfree(buffer_norm); + myfree(buffer_high); } diff --git a/src/util.cpp b/src/util.cpp index 952331dc..ab9e0eec 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -119,16 +119,6 @@ void myunquote(std::string &parm) } -/* Free memory and set the pointer to NULL*/ -void myfree(void *ptr_addr) { - void **ptr = (void **)ptr_addr; - - if (*ptr != NULL) { - free(*ptr); - *ptr = NULL; - } -} - /** mymalloc */ void *mymalloc(size_t nbytes) { diff --git a/src/util.hpp b/src/util.hpp index 39a84eb1..b57e0b26 100644 --- a/src/util.hpp +++ b/src/util.hpp @@ -74,7 +74,7 @@ typedef const uint8_t myuint; #endif - void myfree(void *ptr_addr); + #define myfree(x) {if(x!=nullptr) {free(x); x=nullptr;}} #define mydelete(x) {if(x!=nullptr) {delete x; x=nullptr;}} void *mymalloc(size_t nbytes); diff --git a/src/video_v4l2.cpp b/src/video_v4l2.cpp index 3448fe57..14677f11 100644 --- a/src/video_v4l2.cpp +++ b/src/video_v4l2.cpp @@ -779,7 +779,7 @@ void cls_v4l2cam::set_mmap() MOTPLS_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO ,_("Error querying buffer %i\nVIDIOC_QUERYBUF: ") ,buffer_index); - myfree(&buffers); + myfree(buffers); device_close(); return; } @@ -792,7 +792,7 @@ void cls_v4l2cam::set_mmap() if (buffers[buffer_index].ptr == MAP_FAILED) { MOTPLS_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO ,_("Error mapping buffer %i mmap"), buffer_index); - myfree(&buffers); + myfree(buffers); device_close(); return; } @@ -1109,7 +1109,7 @@ void cls_v4l2cam::stop_cam() for (indx = 0; indx < (int)vidreq.count; indx++){ munmap(buffers[indx].ptr, buffers[indx].size); } - myfree(&buffers); + myfree(buffers); } if (convert != nullptr) { diff --git a/src/webu_ans.cpp b/src/webu_ans.cpp index 3f6c05fc..34bf92c2 100644 --- a/src/webu_ans.cpp +++ b/src/webu_ans.cpp @@ -410,10 +410,10 @@ mhdrslt cls_webu_ans::mhd_digest() /* Check for valid user name */ if (mystrne(user, auth_user)) { failauth_log(true); - myfree(&user); + myfree(user); return mhd_digest_fail(MHD_NO); } - myfree(&user); + myfree(user); /* Check the password as well*/ retcd = MHD_digest_auth_check(connection, auth_realm @@ -470,20 +470,20 @@ mhdrslt cls_webu_ans::mhd_basic() user = MHD_basic_auth_get_username_password (connection, &pass); if ((user == NULL) || (pass == NULL)) { - myfree(&user); - myfree(&pass); + myfree(user); + myfree(pass); return mhd_basic_fail(); } if ((mystrne(user, auth_user)) || (mystrne(pass, auth_pass))) { failauth_log(mystrne(user, auth_user)); - myfree(&user); - myfree(&pass); + myfree(user); + myfree(pass); return mhd_basic_fail(); } - myfree(&user); - myfree(&pass); + myfree(user); + myfree(pass); authenticated = true; @@ -497,8 +497,8 @@ void cls_webu_ans::mhd_auth_parse() int auth_len; char *col_pos; - myfree(&auth_user); - myfree(&auth_pass); + myfree(auth_user); + myfree(auth_pass); auth_len = (int)app->conf->webcontrol_authentication.length(); col_pos =(char*) strstr(app->conf->webcontrol_authentication.c_str() ,":"); @@ -821,8 +821,8 @@ void cls_webu_ans::deinit_counter() (strm->jpg_cnct == 0) && (strm->ts_cnct == 0) && (p_cam->passflag)) { - myfree(&strm->img_data); - myfree(&strm->jpg_data); + myfree(strm->img_data); + myfree(strm->jpg_data); } pthread_mutex_unlock(&p_cam->stream.mutex); } @@ -848,9 +848,9 @@ cls_webu_ans::~cls_webu_ans() delete webu_stream; } - myfree(&auth_user); - myfree(&auth_pass); - myfree(&auth_opaque); - myfree(&auth_realm); + myfree(auth_user); + myfree(auth_pass); + myfree(auth_opaque); + myfree(auth_realm); webu->cnct_cnt--; } \ No newline at end of file diff --git a/src/webu_common.cpp b/src/webu_common.cpp index e648ebfb..7ea60bde 100644 --- a/src/webu_common.cpp +++ b/src/webu_common.cpp @@ -355,8 +355,8 @@ void cls_webu_common::all_getimg() } } - myfree(&dst_img); - myfree(&src_img); + myfree(dst_img); + myfree(src_img); } } @@ -558,7 +558,7 @@ void cls_webu_common::one_buffer() } if (resp_size < (size_t)webua->cam->imgs.size_norm) { if (resp_image != NULL) { - myfree(&resp_image); + myfree(resp_image); } resp_image = (unsigned char*) mymalloc((uint)webua->cam->imgs.size_norm); memset(resp_image,'\0', (uint)webua->cam->imgs.size_norm); @@ -571,7 +571,7 @@ void cls_webu_common::all_buffer() { if (resp_size < (size_t)app->all_sizes->img_sz) { if (resp_image != nullptr) { - myfree(&resp_image); + myfree(resp_image); } resp_size = (uint)app->all_sizes->img_sz; resp_image = (unsigned char*) mymalloc(resp_size); @@ -603,6 +603,6 @@ cls_webu_common::~cls_webu_common() app = nullptr; webu = nullptr; webua = nullptr; - myfree(&resp_image); - myfree(&all_img_data); + myfree(resp_image); + myfree(all_img_data); } diff --git a/src/webu_getimg.cpp b/src/webu_getimg.cpp index 42e3dad1..878905e1 100644 --- a/src/webu_getimg.cpp +++ b/src/webu_getimg.cpp @@ -79,20 +79,20 @@ void webu_getimg_init(ctx_dev *cam) void webu_getimg_deinit(ctx_dev *cam) { /* NOTE: This runs on the motion_loop thread. */ - myfree(&cam->imgs.image_substream); + myfree(cam->imgs.image_substream); pthread_mutex_lock(&cam->stream.mutex); - myfree(&cam->stream.norm.jpg_data); - myfree(&cam->stream.sub.jpg_data); - myfree(&cam->stream.motion.jpg_data); - myfree(&cam->stream.source.jpg_data); - myfree(&cam->stream.secondary.jpg_data); + myfree(cam->stream.norm.jpg_data); + myfree(cam->stream.sub.jpg_data); + myfree(cam->stream.motion.jpg_data); + myfree(cam->stream.source.jpg_data); + myfree(cam->stream.secondary.jpg_data); - myfree(&cam->stream.norm.img_data) ; - myfree(&cam->stream.sub.img_data) ; - myfree(&cam->stream.motion.img_data) ; - myfree(&cam->stream.source.img_data) ; - myfree(&cam->stream.secondary.img_data) ; + myfree(cam->stream.norm.img_data) ; + myfree(cam->stream.sub.img_data) ; + myfree(cam->stream.motion.img_data) ; + myfree(cam->stream.source.img_data) ; + myfree(cam->stream.secondary.img_data) ; pthread_mutex_unlock(&cam->stream.mutex); pthread_mutex_destroy(&cam->stream.mutex); @@ -299,7 +299,7 @@ static void webu_getimg_secondary(ctx_dev *cam) cam->stream.secondary.jpg_sz = cam->imgs.size_secondary; pthread_mutex_unlock(&cam->algsec->mutex); } else { - myfree(&cam->stream.secondary.jpg_data); + myfree(cam->stream.secondary.jpg_data); } } if ((cam->stream.secondary.ts_cnct > 0) || (cam->stream.secondary.all_cnct > 0)) { diff --git a/src/webu_mpegts.cpp b/src/webu_mpegts.cpp index ddebb047..48ef4d13 100644 --- a/src/webu_mpegts.cpp +++ b/src/webu_mpegts.cpp @@ -190,10 +190,10 @@ int cls_webu_mpegts::getimg() } if (pic_send(img_data) < 0) { - myfree(&img_data); + myfree(img_data); return -1; } - myfree(&img_data); + myfree(img_data); if (pic_get() < 0) { return -1; diff --git a/src/webu_post.cpp b/src/webu_post.cpp index 88c50363..21ea62ac 100644 --- a/src/webu_post.cpp +++ b/src/webu_post.cpp @@ -774,8 +774,8 @@ cls_webu_post::~cls_webu_post() } for (indx = 0; indxresp_image + header_len, jpg_data, (uint)jpg_sz); memcpy(webuc->resp_image + header_len + jpg_sz,"\r\n",(uint)2); webuc->resp_used =(uint)(header_len + jpg_sz + 2); - myfree(&jpg_data); + myfree(jpg_data); } @@ -245,7 +245,7 @@ void cls_webu_stream::static_all_img() , all_sz->img_sz, webuc->all_img_data, all_sz->width , all_sz->height, 70, NULL,NULL,NULL); memcpy(webuc->resp_image, jpg_data, webuc->resp_used); - myfree(&jpg_data); + myfree(jpg_data); } /* Increment the jpg stream counters */