Skip to content

Commit

Permalink
Merge pull request #464 from bluecherrydvr/buffer_append_fix
Browse files Browse the repository at this point in the history
Fixed buffer append crash
  • Loading branch information
curtishall authored Jun 13, 2021
2 parents 10d3d75 + 91906b3 commit 67b454d
Show file tree
Hide file tree
Showing 19 changed files with 265 additions and 117 deletions.
12 changes: 12 additions & 0 deletions debian/bluecherry.preinst.template
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@
# Note: this template file is prepended with misc/sql/load_db_creds.sh at packaging stage.
# So "$dbname", "$user", "$password" variables are available.

if [[ $(cat /etc/os-release | grep "^ID=" | grep centos) ]]
then
systemctl stop httpd.service
else
if [ ! -z `which service` ]
then
service apache2 stop || true
else
invoke-rc.d apache2 stop || true
fi
fi

if [ "$1" = upgrade ] && dpkg --compare-versions "$2" lt "1:2.0.3"; then
echo "UPGRADES WILL NOT WORK!!"
echo "Please 'dpkg -P bluecherry' before installing this new package"
Expand Down
7 changes: 7 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
bluecherry (3:3.1.0-rc2) focal bionic buster groovy hirsute bullseye; urgency=low

* FIX: Resolve large memory leak, causing OOM failure sometimes as soon as 1 hour. (https://github.com/bluecherrydvr/bluecherry-apps/commit/01328270cba757fd853c84826402d44dc0d3eb61) / #01328270cba757fd853c84826402d44dc0d3eb61
* FIX: Resolve buffer append crash (#6bc8ceed0b5bd6385991bd1dea65f36bffeea782)

-- Curtis Hall <[email protected]> Wed, 12 Jun 2021 15:52:04 -0600

bluecherry (3:3.1.0-rc1) focal bionic buster groovy; urgency=low

* FEATURE: Migrate completely to nginx instead of Apache (#436)
Expand Down
2 changes: 2 additions & 0 deletions debian/control.in
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ Depends: ${shlibs:Depends}, ssl-cert, ucf, curl, sysstat,
mkvtoolnix, php-mail, php-mail-mime, php-net-smtp, sqlite3, nmap,
nginx,
php-fpm,
php-mysql,
php-sqlite3,
v4l-utils,
vainfo,
i965-va-driver,
Expand Down
9 changes: 8 additions & 1 deletion lib/BCMK
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
LDFLAGS += -L/usr/lib64/mysql -lmysqlclient -lconfig -lm -lrt -lbsd
ifeq ($(BC_DEBIAN_BULLSEYE),y)
CFLAGS += -DBC_USE_MARIADB=y
LDFLAGS += -L/usr/lib64/mariadb -lmariadbclient
else
LDFLAGS += -L/usr/lib64/mysql -lmysqlclient
endif

LDFLAGS += -lconfig -lm -lrt -lbsd
LDFLAGS += -lavutil -lavformat -lavcodec -lpugixml
CFLAGS += -fPIC -DETCDIR="\"$(etc_dir)\""

Expand Down
6 changes: 6 additions & 0 deletions lib/bc-db-mysql.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,15 @@

#include "bc-db.h"

#ifdef BC_USE_MARIADB
#include <mariadb/mysql.h>
#include <mariadb/errmsg.h>
#include <mariadb/mysqld_error.h>
#else
#include <mysql/mysql.h>
#include <mysql/errmsg.h>
#include <mysql/mysqld_error.h>
#endif

struct bc_db_mysql_res {
MYSQL_RES *res;
Expand Down
8 changes: 6 additions & 2 deletions lib/input_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,10 @@ void stream_properties::video_properties::apply(AVCodecContext *cc) const
cc->profile = profile;
if (!extradata.empty()) {
cc->extradata_size = extradata.size();
cc->extradata = (uint8_t*)av_malloc(extradata.size() + AV_INPUT_BUFFER_PADDING_SIZE);
size_t size = extradata.size() + AV_INPUT_BUFFER_PADDING_SIZE;
cc->extradata = (uint8_t*)av_malloc(size);
memcpy(cc->extradata, &extradata.front(), extradata.size());
memset(cc->extradata + extradata.size(), 0, AV_INPUT_BUFFER_PADDING_SIZE);
} else {
cc->extradata_size = 0;
cc->extradata = 0;
Expand All @@ -221,8 +223,10 @@ void stream_properties::audio_properties::apply(AVCodecContext *cc) const
cc->bits_per_coded_sample = bits_per_coded_sample;
if (!extradata.empty()) {
cc->extradata_size = extradata.size();
cc->extradata = (uint8_t*)av_malloc(extradata.size() + AV_INPUT_BUFFER_PADDING_SIZE);
size_t size = extradata.size() + AV_INPUT_BUFFER_PADDING_SIZE;
cc->extradata = (uint8_t*)av_malloc(size);
memcpy(cc->extradata, &extradata.front(), extradata.size());
memset(cc->extradata + extradata.size(), 0, AV_INPUT_BUFFER_PADDING_SIZE);
} else {
cc->extradata_size = 0;
cc->extradata = 0;
Expand Down
11 changes: 7 additions & 4 deletions nginx-configs/php/bullseye.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php7.4-fpm.sock;
fastcgi_index index.php;
location ~ \.php$ {
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi.conf;
set $path_info $fastcgi_path_info;
fastcgi_param PATH_INFO $path_info;
fastcgi_param SCRIPT_FILENAME $document_root/index.php;
fastcgi_index index.php;
}
14 changes: 9 additions & 5 deletions nginx-configs/php/buster.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php7.3-fpm.sock;
fastcgi_index index.php;
location ~ \.php$ {
fastcgi_pass unix:/run/php/php7.3-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi.conf;
}
set $path_info $fastcgi_path_info;
fastcgi_param PATH_INFO $path_info;
fastcgi_param SCRIPT_FILENAME $document_root/index.php;
fastcgi_index index.php;
}

8 changes: 7 additions & 1 deletion scripts/build_helper/post_make_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,13 @@ then

mkdir -p ${DST_DIR}/usr/share/bluecherry/nginx-includes/
cp ${SRC_PATH}/nginx-configs/php/* ${DST_DIR}/usr/share/bluecherry/nginx-includes/
_CODENAME_=`cat /etc/os-release | grep UBUNTU_CODENAME | cut -d = -f 2`

if [[ $(cat /etc/os-release | grep "^ID=" | grep debian) ]]
then
_CODENAME_=`cat /etc/os-release | grep VERSION_CODENAME | cut -d = -f 2`
else
_CODENAME_=`cat /etc/os-release | grep UBUNTU_CODENAME | cut -d = -f 2`
fi

mkdir -p ${DST_DIR}/etc/nginx/sites-enabled/
cat ${SRC_PATH}/nginx-configs/bluecherry.conf | sed \
Expand Down
7 changes: 7 additions & 0 deletions scripts/build_pkg_native.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ else
sudo `dirname $0`/install_prereqs_native.sh
fi

if [[ $(cat /etc/os-release | grep "^ID=" | grep debian) && \
$(cat /etc/os-release | grep "^VERSION=" | grep 11) ]]
then
apt-get install -y libmariadb-dev
export BC_DEBIAN_BULLSEYE=y
fi

# TODO Implement building outside of sources tree

# Safety measures. TODO quick compilation without spare rebuilds
Expand Down
3 changes: 0 additions & 3 deletions server/BCMK
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ LDFLAGS += -lopencv_core -lopencv_imgproc -lopencv_imgcodecs
BC_VERSION := $(shell sed 's/.*([^:]*://;s/-[^()]*//;s/).*//;q' $(TOPDIR)/debian/changelog)
CFLAGS += -DBC_VERSION='"$(BC_VERSION)"'

# Enable SSL/TLS support for HLS
CFLAGS += -DBC_HLS_WITH_SSL=y

TARGETS = bc-server
SERVER_OBJS = bc-server.o bc-thread.o media_writer.o g723-dec.o \
bc-detect.o streaming.o rtsp.o signals.o motion_processor.o trigger_processor.o \
Expand Down
5 changes: 4 additions & 1 deletion server/bc-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -858,10 +858,10 @@ static int bc_initial_cleanup_untracked_media()
}

const char *filepath = bc_db_get_val(dbres, "filepath", NULL);
bc_db_free_table(dbres);

if (!filepath || !*filepath) {
bc_log(Warning, "Failed to read oldest file path");
bc_db_free_table(dbres);
return -1;
}

Expand All @@ -879,6 +879,7 @@ static int bc_initial_cleanup_untracked_media()

if (count != 7) {
bc_log(Warning, "Failed determine oldest media time");
bc_db_free_table(dbres);
return -1;
}

Expand All @@ -887,6 +888,7 @@ static int bc_initial_cleanup_untracked_media()

if (!bc_get_media_locations(locations)) {
bc_log(Warning, "No media locations available for cleanup");
bc_db_free_table(dbres);
return -1;
}

Expand All @@ -896,6 +898,7 @@ static int bc_initial_cleanup_untracked_media()
bc_log(Info, "Initial media cleanup finished: removed(%d), archived(%d), errors(%d), others(%d)",
ctx.removed, ctx.archived, ctx.errors, ctx.others);

bc_db_free_table(dbres);
return 0;
}

Expand Down
6 changes: 6 additions & 0 deletions server/bc-thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ void stop_handle_properly(struct bc_record *bc_rec)

bc_streaming_destroy_hls(bc_rec);

if (bc_rec->hls_stream)
{
hls_content *content = bc_rec->hls_stream->get_hls_content(bc_rec->id);
if (content) content->clear_window();
}

if (bc_rec->liveview_substream)
{
bc_rec->liveview_substream->stop();
Expand Down
Loading

0 comments on commit 67b454d

Please sign in to comment.