Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 28 Nov 2018 16:48:41 +0000 (UTC)
From:      Mark Johnston <markj@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org
Subject:   svn commit: r341150 - stable/12/sys/kern
Message-ID:  <201811281648.wASGmfLc089027@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: markj
Date: Wed Nov 28 16:48:40 2018
New Revision: 341150
URL: https://svnweb.freebsd.org/changeset/base/341150

Log:
  MFC r339497 (by cem):
  ZSTDIO: Correctly initialize zstd context with provided 'level'

Modified:
  stable/12/sys/kern/subr_compressor.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/sys/kern/subr_compressor.c
==============================================================================
--- stable/12/sys/kern/subr_compressor.c	Wed Nov 28 16:20:04 2018	(r341149)
+++ stable/12/sys/kern/subr_compressor.c	Wed Nov 28 16:48:40 2018	(r341150)
@@ -275,8 +275,9 @@ zstdio_init(size_t maxiosize, int level)
 	ZSTD_CCtx *dump_compressor;
 	struct zstdio_stream *s;
 	void *wkspc, *owkspc, *buffer;
-	size_t wkspc_size, buf_size;
+	size_t wkspc_size, buf_size, rc;
 
+	s = NULL;
 	wkspc_size = ZSTD_estimateCStreamSize(level);
 	owkspc = wkspc = malloc(wkspc_size + 8, M_COMPRESS,
 	    M_WAITOK | M_NODUMP);
@@ -286,12 +287,23 @@ zstdio_init(size_t maxiosize, int level)
 
 	dump_compressor = ZSTD_initStaticCCtx(wkspc, wkspc_size);
 	if (dump_compressor == NULL) {
-		free(owkspc, M_COMPRESS);
 		printf("%s: workspace too small.\n", __func__);
-		return (NULL);
+		goto out;
 	}
 
-	(void)ZSTD_CCtx_setParameter(dump_compressor, ZSTD_p_checksumFlag, 1);
+	rc = ZSTD_CCtx_setParameter(dump_compressor, ZSTD_p_checksumFlag, 1);
+	if (ZSTD_isError(rc)) {
+		printf("%s: error setting checksumFlag: %s\n", __func__,
+		    ZSTD_getErrorName(rc));
+		goto out;
+	}
+	rc = ZSTD_CCtx_setParameter(dump_compressor, ZSTD_p_compressionLevel,
+	    level);
+	if (ZSTD_isError(rc)) {
+		printf("%s: error setting compressLevel: %s\n", __func__,
+		    ZSTD_getErrorName(rc));
+		goto out;
+	}
 
 	buf_size = ZSTD_CStreamOutSize() * 2;
 	buffer = malloc(buf_size, M_COMPRESS, M_WAITOK | M_NODUMP);
@@ -306,6 +318,9 @@ zstdio_init(size_t maxiosize, int level)
 
 	zstdio_reset(s);
 
+out:
+	if (s == NULL)
+		free(owkspc, M_COMPRESS);
 	return (s);
 }
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201811281648.wASGmfLc089027>