Skip to content

Commit

Permalink
Revise myfree method
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-Dave committed Jul 25, 2024
1 parent 5032b15 commit 29112ee
Show file tree
Hide file tree
Showing 17 changed files with 88 additions and 98 deletions.
2 changes: 1 addition & 1 deletion src/alg_sec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions src/conf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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; indx<motapp->snd_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;

}
Expand Down
18 changes: 9 additions & 9 deletions src/dbse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ static void dbse_cols_free(ctx_motapp *motapp)

if (motapp->dbse->cols_list != NULL) {
for (indx=0; indx<motapp->dbse->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;

Expand All @@ -86,14 +86,14 @@ static void dbse_movies_free(ctx_motapp *motapp)

if (motapp->dbse->movie_list != NULL) {
for (indx=0; indx<motapp->dbse->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;

Expand Down
6 changes: 3 additions & 3 deletions src/jpegutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
44 changes: 22 additions & 22 deletions src/motion_loop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 */

Expand Down
2 changes: 1 addition & 1 deletion src/motionplus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/netcam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -449,7 +449,7 @@ void cls_netcam::pktarray_resize()
tmp[indx].iswritten = false;
}

myfree(&pktarray);
myfree(pktarray);
pktarray = tmp;
pktarray_size = newsize;

Expand Down
4 changes: 2 additions & 2 deletions src/rotate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}
10 changes: 0 additions & 10 deletions src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/video_v4l2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand Down
32 changes: 16 additions & 16 deletions src/webu_ans.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand All @@ -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() ,":");
Expand Down Expand Up @@ -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);
}
Expand All @@ -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--;
}
12 changes: 6 additions & 6 deletions src/webu_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,8 @@ void cls_webu_common::all_getimg()
}
}

myfree(&dst_img);
myfree(&src_img);
myfree(dst_img);
myfree(src_img);
}

}
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
}
26 changes: 13 additions & 13 deletions src/webu_getimg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.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.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) ;
pthread_mutex_unlock(&cam->stream.mutex);

pthread_mutex_destroy(&cam->stream.mutex);
Expand Down Expand Up @@ -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)) {
Expand Down
4 changes: 2 additions & 2 deletions src/webu_mpegts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading

0 comments on commit 29112ee

Please sign in to comment.